POJ1548
来源:互联网 发布:南泥湾种鸦片 知乎 编辑:程序博客网 时间:2024/06/02 04:08
Problem : Robots
Description : 一些机器人清理矩阵中的垃圾,机器人只能往下走和往右走。现在所有的机器人一开始都在左上角。现在问你最少需要多少个机器人才能清理所有的垃圾。
Solution : 二分图的最小路径覆盖。构图就不多说了,但是要注意的是我们连边的时候要往下和右这两个方向连,遇到第一个垃圾就停止连边了。两个垃圾有可能在矩形的对角上,这两个垃圾是可以连边的,这一点要特别注意!
Code(C++) :
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <string>#include <vector>#define MIN(a,b) ((a)>(b)? (b):(a))using namespace std;const int F=25*25+5;const int E=25+5;const int INF=0x3f3f3f3f;typedef struct tagNode{ int p,t,d; tagNode(){} tagNode(int P,int T,int D): p(P),t(T),d(D){}}Node;int n;vector<int> edge[F];bool used[F];int belong[F];Node line[F];int map[E][E];bool cmp(Node a,Node b){ return a.t<b.t;}bool dfs(int s){ for(int i=0;i<edge[s].size();i++){ int end=edge[s].at(i); if(used[end]) continue; used[end]=true; if(belong[end]==-1||dfs(belong[end])){ belong[end]=s; return true; } } return false;}int main(){ //freopen("in.data","r",stdin); int x,y; while(scanf("%d%d",&x,&y),!(x==-1&&y==-1)){ memset(map,0,sizeof(map)); n=0; map[x][y]=++n; for(int i=0;i<F;i++) edge[i].clear(); memset(belong,-1,sizeof(belong)); while(scanf("%d%d",&x,&y),!(!x&&!y)) map[x][y]=++n; for(int i=1;i<E;i++) for(int j=1;j<E;j++) if(map[i][j]){ for(int y=j+1;y<E;y++) if(map[i][y]){ edge[map[i][j]].push_back(map[i][y]); break; }else{ for(int x=i+1;x<E;x++) if(map[x][y]){ edge[map[i][j]].push_back(map[x][y]); break; } } for(int x=i+1;x<E;x++) if(map[x][j]){ edge[map[i][j]].push_back(map[x][j]); break; }else{ for(int y=j+1;y<E;y++) if(map[x][y]){ edge[map[i][j]].push_back(map[x][y]); break; } } } int sum=0; for(int i=1;i<=n;i++){ memset(used,false,sizeof(used)); if(dfs(i)) ++sum; } printf("%d\n",n-sum); } return 0;}
0 0
- poj1548
- poj1548
- POJ1548
- poj1548 - Robots
- poj1548 Robots
- poj1548 Robots
- poj1548最小路径覆盖
- poj1548 A strange lift
- POJ1548最小路径覆盖
- POJ1548-Robots Dilworth 定理
- poj1548(最小路径覆盖)
- Robots(Poj1548)(贪心)
- poj1548(最短路)-惯性思维
- POJ1548 Robots【二分图最小路径覆盖】
- 【POJ1548】Robots Dilworth定理(偏序集定理2)
- ajax之原理
- super和this的比较
- hdu 2147 kiki's game 巴什博弈
- 第二次 尝试 我的
- 调试小技巧
- POJ1548
- 解决bash: mysql: command not found 的方法
- 《性能测试》之理发店模型
- iOS代理设计模式
- Django入门:python manage.py dbshell错误
- Stay Hungry. Stay Foolish.
- 克里斯航沥斯夫斯基定律------------原创
- 列表、元组以及字符串
- cygwin 2.8.74版本离线包(分别为win7 32和64位)