【图论】[ZOJ1054]Place the Robots
来源:互联网 发布:javascript播放器下载 编辑:程序博客网 时间:2024/05/30 05:01
题目
分析:二分图匹配,和ZOJ1052差不多,但是草地在计算连通块是当做空地,在连边是如果交点是草地则不连边。
代码:
#include<cstdio>#include<cstring>#define MAXN 50int n,a[MAXN+10][MAXN+10],cnt,cnt1,c[MAXN*MAXN*2+10],ans,T,m;char s[MAXN+10][MAXN+10];bool vis[MAXN*MAXN*2+10];struct node{ int v; node *next;}edge[MAXN*MAXN*MAXN*MAXN/4+10],*adj[MAXN*MAXN*2+10],*ecnt=edge;void addedge(int u,int v){ node *p=++ecnt; p->v=v; p->next=adj[u]; adj[u]=p;}bool dfs(int u){ int v; for(node *p=adj[u];p;p=p->next){ v=p->v; if(!vis[v]){ vis[v]=1; if(!c[v]||dfs(c[v])){ c[u]=v; c[v]=u; return 1; } } } return 0;}void maxmatch(){ for(int i=1;i<=cnt1;i++){ memset(vis,0,sizeof vis); if(!c[i]&&dfs(i)) ans++; }}int main(){ int i,j,tcnt=0; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); memset(c,0,sizeof c); memset(adj,0,sizeof adj); memset(a,0,sizeof a); ans=cnt=0; ecnt=edge; for(i=1;i<=n;i++) scanf("%s",s[i]+1); for(i=1;i<=n;i++) for(j=1;j<=m;j++){ if(s[i][j]=='#') continue; if(!s[i][j-1]||s[i][j-1]=='#') cnt++; if(s[i][j]=='*') continue; a[i][j]=cnt; } cnt1=cnt; for(j=1;j<=m;j++) for(i=1;i<=n;i++){ if(s[i][j]=='#') continue; if(!s[i-1][j]||s[i-1][j]=='#') cnt++; if(s[i][j]=='*') continue; addedge(a[i][j],cnt); addedge(cnt,a[i][j]); } maxmatch(); printf("Case :%d\n%d\n",++tcnt,ans); }}
0 0
- 【图论】[ZOJ1054]Place the Robots
- ZOJ1654:Place the Robots
- zoj1654 Place the Robots
- Place the Robots
- ZOJ1654 Place the Robots
- ZOJ1654 Place the Robots
- ZOJ1654 Place the Robots
- Place the Robots ZOJ1645
- zoj 1654 Place the Robots
- zoj 1654 Place the Robots
- zoj 1654 Place the Robots
- ZOJ 1654 Place the Robots
- Place the Robots zoj 1654
- ZOJ 1654 Place the Robots
- ZOJ 1654 Place the Robots
- ZOJ 1654 Place the Robots
- ZOJ 1654 Place the Robots
- 【图论】【二分图匹配】[ZOJ 1654]Place the Robots
- C++中的指针和指针的引用
- 如何理解file‘s owner
- Masonry介绍与使用实践:快速上手Autolayout
- 安装Android Studio结束时提示VT is not enabled in the system
- 2015 多校联赛 ——HDU5410(dp)
- 【图论】[ZOJ1054]Place the Robots
- 浅谈 OneAPM 在 express 项目中的实践
- makefile include的作用
- HDU 5371(Hotaru's problem-2次回文串)
- UIWindow
- 【问底】徐汉彬:Web系统大规模并发——电商秒杀与抢购
- 电子商务的本质是低成本高效率
- 安卓FragmentManager中FragmentTransaction的介绍
- UI空间大全