POJ 2594 Treasure Exploration
来源:互联网 发布:利用淘宝漏洞赚钱 编辑:程序博客网 时间:2024/05/17 08:33
POJ 2594 Treasure Exploration
题目链接:POJ 2594
题意:
使最少的机器人参观完n个点,在通过的道路中,机器人只可以一端到另一端,不能往后走,机器人之间通过的点可能相同。
分析:
最小路径覆盖数=最大匹配数
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n,m,s,v;// BFSconst int maxn=512;int g[maxn][maxn];int L,R;int x[maxn],y[maxn];int Q[maxn]; //模拟队列int pre[maxn];int MaxMatch(){ int res=0,temp;memset(x,-1,sizeof(x));memset(y,-1,sizeof(y));for(int i=1;i<=L;i++){if(x[i]==-1){int cur=0,tail=0;for(int j=1;j<=R;j++){if(g[i][j])pre[j]=-1,Q[tail++]=j;else pre[j]=-2;}//BFSwhile(cur<tail){temp=Q[cur];if(y[temp]==-1)break;cur++;for(int j=1;j<=R;j++){if(pre[j]==-2&&g[y[temp]][j]){pre[j]=temp;Q[tail++]=j;}}}//end of BFSif(cur==tail) //没有找到交错轨continue;while(pre[temp]>-1) //更改交错轨上匹配状态{x[ y[pre[temp]] ]=temp;y[temp]=y[pre[temp]];temp=pre[temp];}y[temp]=i;x[i]=temp;res++;}}return res;}int main(){// freopen("in.txt","r",stdin);int u,v; while(scanf("%d %d",&n,&m)!=EOF&&(n||m)){memset(g,0,sizeof(g));for(int i=0;i<m;i++){scanf("%d %d",&u,&v);g[u][v]=1;}for(int k=1;k<=n;k++) //floyd构图(中间许多过程点){for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(k==i||k==j) continue;if(g[i][k]==1&&g[k][j]==1)g[i][j]=1;}}}L=R=n;printf("%d\n",n-MaxMatch());}return 0;}
0 0
- poj 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- POJ--2594|Treasure Exploration
- POJ 2594 Treasure Exploration 最小路径覆盖
- poj 2594 Treasure Exploration 二分图匹配
- poj 2594 Treasure Exploration(好题)
- poj 2594 Treasure Exploration 二分匹配
- 是tomcat的lib文件夹jar包和项目的lib文件下的jar包冲突了
- 黑马程序员——Java练习笔记——继承
- 使用PowerDesigner把oom设计图导出jpg格式的图片
- 线段覆盖
- 阿里巴巴公司内部资料:交互设计全档案
- POJ 2594 Treasure Exploration
- AOJ0009Prime Number
- 集合详解(三):Set
- c#中的类型转换
- 安卓作业
- JAVA读取PDF信息
- Android 开发 短信app
- 移动机器人控制的基本介绍
- POJ 3130 || How I Mathematician Wonder What You Are!