poj 1548 Robots 最小路径覆盖
来源:互联网 发布:电子cad软件 编辑:程序博客网 时间:2024/05/16 13:42
题意:
在一个n*m矩阵里有一些垃圾,现在要用机器人把它们清理掉,机器人的起点是(1,1),终点是(n,m),而且机器人必须按坐标不减的方向行走,每个机器人可以清理他走过路上所有的垃圾,现在要求最少需要多少个机器人。
思路;
把每个需要清理的地方看做点,如果机器人能从点a走到b则有一条边由a指向b,这样建图后原问题等价于求这个有向无环图的最小路径覆盖,直接用匈牙利算法即可。
代码:
//poj 1548 by sepNINE#include<iostream>using namespace std;const int maxN=640;struct Point{int x,y;}pnt[maxN]; int v1,v2,M;bool g[maxN][maxN];bool vis[maxN];int link[maxN];bool dfs(int x){for(int y=1;y<=v2;++y)if(g[x][y]&&!vis[y]){vis[y]=true;if(link[y]==0||dfs(link[y])){link[y]=x;return true;}}return false;}void hungary(){for(int x=1;x<=v1;++x){memset(vis,false,sizeof(vis));if(dfs(x))++M;}return ;}int main(){int xx,yy,cnt=0;while(scanf("%d%d",&xx,&yy)==2){if(xx==-1)break;if(xx==0&&yy==0){memset(g,false,sizeof(g));memset(link,0,sizeof(link));int i,j;for(i=1;i<=cnt;++i)for(j=i+1;j<=cnt;++j){if(pnt[j].x>=pnt[i].x&&pnt[j].y>=pnt[i].y)g[i][j]=1;if(pnt[i].x>=pnt[j].x&&pnt[i].y>=pnt[j].y)g[j][i]=1;}v1=v2=cnt;M=0;hungary();printf("%d\n",cnt-M);cnt=0;continue;}pnt[++cnt].x=xx;pnt[cnt].y=yy;}return 0;}
0 0
- POJ 1548 Robots(DAG最小路径覆盖)
- poj 1548 Robots 最小路径覆盖
- POJ 1548 Robots(最小路径覆盖)
- poj 1548 Robots(最小路径覆盖)
- POJ 1548 Robots(DAG最小路径覆盖)
- poj 1548 Robots 最小路径覆盖
- POJ-1548-Robots(最小路径覆盖)
- POJ 1548 Robots(DAG最小路径覆盖)
- POJ - 1548 Robots 二分图 最小路径覆盖
- poj-1548-Robots- 贪心+模拟 / 最小路径覆盖
- Poj 1548 Robots【最小路径覆盖---二分匹配】
- 【二分图+最小路径覆盖+建图难度】北大 poj 1548 Robots
- poj 1548 Robots 最小路径匹配解法
- POJ 1548 最小路径覆盖
- poj 1548(最小路径覆盖)
- poj 1548最小路径覆盖
- POJ1548 Robots【二分图最小路径覆盖】
- poj 2060(最小路径覆盖)
- python 定义函数
- PHP之道
- Android代码优化(一)
- 记忆深刻的菱形结构
- hdu 1044Collect More Jewels(bfs+dfs)
- poj 1548 Robots 最小路径覆盖
- hibernate之1.环境搭建
- UVA - 439 Knight Moves
- arc strong weak mrc retain
- Find Minimum in Rotated Sorted Array
- python模拟登陆杂记
- localForage Web 离线存储
- SSL certificate problem, verify that the CA cert is OK. Details:
- 2014.10.14错误修改