UVAlive 6156 Sentry Robots
来源:互联网 发布:手机版网络维护软件 编辑:程序博客网 时间:2024/04/30 04:19
题目
题意:
n*m的矩形格子中有一些宝藏,有些点不能经过,每次可以取走一横行,或者一纵行的宝藏,求至少需要多少次取走所有宝藏
题解:
如果没有不能走的点,就是一道经典的二分图匹配的最小点覆盖。考虑障碍,在同一行(或列)被障碍隔开的点就不能算同一行(或列),所以重置坐标即可,进行二分图匹配。
代码:
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 105#define maxm 5005int n,m,k,N,M;int g[maxn][maxn],xx[maxn][maxn],yy[maxn][maxn],result[maxm];bool e[maxm][maxm],state[maxm];int find(int x){ for (int i=1;i<=M;i++) if (!state[i]&&e[x][i]) { state[i]=1; if (!result[i]||find(result[i])) { result[i]=x; return 1; } } return 0;}int hungry(){ int res=0; memset(result,0,sizeof(result)); for (int i=1;i<=N;i++) { memset(state,0,sizeof(state)); if (find(i)) res++; } return res;}int main(){ //freopen("/home/moor/Code/input","r",stdin); int cas,x,y; scanf("%d",&cas); while (cas--) { scanf("%d%d",&n,&m); scanf("%d",&k); memset(g,0,sizeof(g)); for (int i=1;i<=k;i++) { scanf("%d%d",&x,&y); g[x][y]=1; } scanf("%d",&k); for (int i=1;i<=k;i++) { scanf("%d%d",&x,&y); g[x][y]=2; } N=0; for (int i=1;i<=n;i++) { int j=1; while (j<=m) { N++; while (j<=m&&g[i][j]!=2) xx[i][j++]=N; while (j<=m&&g[i][j]==2) j++; } } M=0; for (int i=1;i<=m;i++) { int j=1; while (j<=n) { M++; while (j<=n&&g[j][i]!=2) yy[j++][i]=M; while (j<=n&&g[j][i]==2) j++; } } memset(e,0,sizeof(e)); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (g[i][j]==1) e[xx[i][j]][yy[i][j]]=1; printf("%d\n",hungry()); } return 0;}
- UVAlive 6156 Sentry Robots
- Sentry Robots
- Sentry Robots UVA
- Sentry Robots UVA
- ACM->uvalive->Sentry Robots(二分图匹配的最小点覆盖)
- UVA 12549(p381)----Sentry Robots
- 12549 - Sentry Robots (二分图匹配)
- uva 12549 Sentry Robots 最大二分匹配
- UVA 12549 Sentry Robots 最小点集覆盖
- Uva 12549 Sentry Robots 网络流 - 二分图匹配
- Sentry Robots, ACM/ICPC SWERC 2012, UVa12549 【二分图】
- sentry
- UVALive 7464 - Robots (思路+模拟)
- 【UVALive 7364】Robots(逆向思维+搜索)
- Sentry Robots 组队赛第二场 Regionals 2012, Europe - Southwestern F题
- [二分图最大匹配=最小覆盖点]uva12549 Sentry Robots
- UVALive-4793 Robots on Ice 搜索加剪枝
- 【uva 12549】Sentry Robots HDU 2119 (hdu 2119Matrix升级版) 最小点覆盖+二分图匹配
- poj 2478 Farey Sequence
- 【乡巴佬】菜鸟收藏:Coreldraw快捷键总集粹
- Struts2中的MethodFilterInterceptor
- Eclipse快捷键
- GMF 界面知识点
- UVAlive 6156 Sentry Robots
- 如何向Android的framework里添加新类
- U-mail V9.8.57版本完美破解
- hdu 2819
- ios动态调整UITableViewCell高度的实现方法
- 简述configure、pkg-config、pkg_config_path三者的关系
- iOS 的多核编程和内存管理
- 将a标签上的手形去掉
- Struts2的Interceptor和Listener以及Plugin