ZOJ 1516 Uncle Tom's Inherited Land
来源:互联网 发布:有c语言基础学java 编辑:程序博客网 时间:2024/06/11 05:02
ZOJ 1516 Uncle Tom's Inherited Land
题目链接:ZOJ 1516
跟ZOJ 1654差不多
#include<cstdio>#include<cstring>using namespace std;const int MAX=201;int n,m;int dr[][2]={{-1,0},{1,0},{0,-1},{0,1}};int sx[MAX],sy[MAX];int t[MAX][MAX];int number;int s[MAX][MAX];// BFSconst int maxn=512;int g[maxn][maxn];int L,R;int x[maxn],y[maxn];int Q[maxn]; //模拟队列int pre[maxn];int MaxMatch(){ int res=0,temp;memset(x,-1,sizeof(x));memset(y,-1,sizeof(y));for(int i=0;i<L;i++){if(x[i]==-1){int cur=0,tail=0;for(int j=0;j<R;j++){if(g[i][j])pre[j]=-1,Q[tail++]=j;else pre[j]=-2;}//BFSwhile(cur<tail){temp=Q[cur];if(y[temp]==-1)break;cur++;for(int j=1;j<=R;j++){if(pre[j]==-2&&g[y[temp]][j]){pre[j]=temp;Q[tail++]=j;}}}//end of BFSif(cur==tail) //没有找到交错轨continue;while(pre[temp]>-1) //更改交错轨上匹配状态{x[ y[pre[temp]] ]=temp;y[temp]=y[pre[temp]];temp=pre[temp];}y[temp]=i;x[i]=temp;res++;}}return res;}int main(){ // freopen("in.txt","r",stdin); int k,u,v; int X,Y; while(scanf("%d %d",&n,&m)!=EOF&&(n||m)) {scanf("%d",&k);memset(t,0,sizeof(t));for(int i=0;i<k;i++){scanf("%d %d",&u,&v);t[u-1][v-1]=1;}number=0;for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(t[i][j]!=1){s[i][j]=number;number++;}}}memset(g,0,sizeof(g));for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(t[i][j]==1) continue;for(int d=0;d<4;d++){X=i+dr[d][0];Y=j+dr[d][1];if(X<0||X>=n||Y<0||Y>=m||t[X][Y]==1) continue;g[s[i][j]][s[X][Y]]=1;}}}L=R=number; printf("%d\n",MaxMatch()/2); } return 0;}
0 0
- ZOJ 1516 Uncle Tom's Inherited Land
- zoj 1516 Uncle Tom's Inherited Land
- 【二分图|最大匹配】ZOJ-1516 Uncle Tom's Inherited Land
- ZOJ 1516 Uncle Tom's Inherited Land(二分匹配 最大匹配 匈牙利啊)
- ZOJ 1516--Uncle Tom's Inherited Land【二分图 && 求最大匹配数 && 经典建图】
- zoj 1516 Uncle Tom's Inherited Land(二分匹配·链式前向星)
- ZOJ 1516 Uncle Tom's Inherited Land (二分图最大匹配)
- ZOJ 1516 Uncle Tom's Inherited Land (二分图匹配)
- HDU 1507 Uncle Tom's Inherited Land*
- hdu 1507 Uncle Tom's Inherited Land*
- hdu Uncle Tom's Inherited Land*
- Hdu1507 Uncle Tom's Inherited Land*
- Hdu 1507 Uncle Tom's Inherited Land*
- HDOJ 1507 Uncle Tom's Inherited Land*
- ZOJ1516 Uncle Tom's Inherited Land
- HDU 1507 Uncle Tom's Inherited Land*
- Hdu 1507 Uncle Tom's Inherited Land*
- Uncle Tom's Inherited Land* 6.3.7
- JSP中访问本地图片
- 单例模式
- iOS:编译问题Presenting view controllers on detached view controllers is discouraged
- #job 41
- linux安装cuda
- ZOJ 1516 Uncle Tom's Inherited Land
- 资产借用归还提醒、员工生日及入职满几年的祝福及祝贺
- Windows Server 2008 下Oracle 11g 定时备份任务
- JAVA 对象序列化
- 变量的存储方式及作用域
- “印刷文化”的光环,没我们想得那么荣耀
- java面试题
- 九章算法面试题20 寻找重复的URL
- 自动消失的弹窗效果