lightoj 1304 The Best Contest Site Ever (二分匹配)
来源:互联网 发布:debug意思网络用语 编辑:程序博客网 时间:2024/05/16 07:21
/*分块 行的快为一方 列的为另一方进行匹配 */# include <stdio.h># include <algorithm># include <string.h>using namespace std;# define N 10010int tot;int head[N];int vis[N];int link[N];int uN;struct node{ int to; int next;} Edge[N<<2];void addEdge(int u,int v){ Edge[tot].to=v; Edge[tot].next=head[u]; head[u]=tot++;}int dfs(int x){ for(int i=head[x]; i!=-1; i=Edge[i].next) { int to=Edge[i].to; if(!vis[to]) { vis[to]=1; if(link[to]==-1||dfs(link[to])) { link[to]=x; return 1; } } } return 0;}int hungary(){ int ans=0; memset(link,-1,sizeof(link)); for(int i=0; i<uN; i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } return ans;}int main(){ int n,m,i,j,t; char a[110][110]; int hang[110][110],lie[110][110]; while(~scanf("%d",&t)) { int cas=0; while(t--) { memset(head,-1,sizeof(head)); tot=0; scanf("%d%d",&n,&m); for(i=0; i<n; i++) scanf("%s",&a[i]); int hh=0; int ll=0; memset(hang,0,sizeof(hang)); memset(lie,0,sizeof(lie)); for(i=0; i<n; i++) { for(j=0; j<m; j++) { if(a[i][j]!='W') { hang[i][j]=hh; if(j==m-1) hh++; } else { if(j!=0&&a[i][j-1]!='#') hh++; } } } for(i=0; i<m; i++) { for(j=0; j<n; j++) { if(a[j][i]!='W') { lie[j][i]=ll; if(j==n-1) ll++; } else { if(j!=0&&a[j-1][i]!='W') ll++; } } } uN=hh; for(i=0; i<n; i++) { for(j=0; j<m; j++) { if(a[i][j]=='.') { addEdge(hang[i][j],lie[i][j]); } } } printf("Case %d: %d\n",++cas,hungary()); for(i=0; i<n; i++) { for(j=0; j<m; j++) { if(a[i][j]=='.'&&link[lie[i][j]]==hang[i][j]) a[i][j]='T'; } } for(i=0;i<n;i++) { for(j=0;j<m;j++) printf("%c",a[i][j]); printf("\n"); } } } return 0;}
0 0
- lightoj 1304 The Best Contest Site Ever (二分匹配)
- LOJ 1304 - The Best Contest Site Ever(二分匹配啊)
- Light OJ 1304 The Best Contest Site Ever 行列匹配变形
- LightOj 1111 - Best Picnic Ever
- LightOJ - 1111 Best Picnic Ever
- LightOJ - 1111 Best Picnic Ever (搜索)
- LightOJ 1111 Best Picnic Ever 简单bfs
- The 46 Best-ever Freeware Utilities
- The 46 Best-ever Freeware Utilities-some
- Oracle Buys Sun: The Best Deal Ever
- The 10 Best MVC Tips Ever
- the best web site for programmer
- The best site to buy wow account
- URAL 1949 The Best Picture in the Galaxy 二分匹配 求字典序最小解
- 50 of the Best Ever MooTools Plugins and Tutorials
- How to Motivate Employees? The Best Answer Ever
- The best article about SVM ever (Chinese version)
- The 7 Best ‘Air Jordan’ Shoes Ever Made
- 有动态画面的安装过程的安装包制作
- Scala入门到精通——第三十节 Scala脚本编程与结束语
- SQL学习笔记
- 剑指offer-二叉搜索树与双向链表
- java中计算两个时间差
- lightoj 1304 The Best Contest Site Ever (二分匹配)
- WIN7(64位)系统发现数据源ODBC里面没有配置access数据源连接&System, System32, Syswow64 概述
- 浅析电子政务工程建设项目的建章立制
- [转]cocos2dx中用外部浏览器打开url
- C语言中的左移与右移
- MySQL Workbench正向逆向工程
- C语言 枚举 enum
- Android中几种图像特效处理的集锦!!
- [iOS]调用系统相机,相册,闪光灯