poj 2594 Treasure Exploration (二分匹配)
| Time Limit: 6000MS | Memory Limit: 65536K | |
| Total Submissions: 6558 | Accepted: 2644 | 
Description
Recently, a company named EUC (Exploring the Unknown Company) plan to explore an unknown place on Mars, which is considered full of treasure. For fast development of technology and bad environment for human beings, EUC sends some robots to explore the treasure.
To make it easy, we use a graph, which is formed by N points (these N points are numbered from 1 to N), to represent the places to be explored. And some points are connected by one-way road, which means that, through the road, a robot can only move from one end to the other end, but cannot move back. For some unknown reasons, there is no circle in this graph. The robots can be sent to any point from Earth by rockets. After landing, the robot can visit some points through the roads, and it can choose some points, which are on its roads, to explore. You should notice that the roads of two different robots may contain some same point.
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars.
As an ICPCer, who has excellent programming skill, can your help EUC?
Input
Output
Sample Input
1 0
2 1
1 2
2 0
0 0
Sample Output
1
1
2
Source
最小路径覆盖(非最小边覆盖):
使用最少的边把所有点覆盖=原点数-最大匹配(修改后的图)
注意一种情况:
5 4
1-->3
2-->3
3-->4
3-->5
这里其实用2个robots就行了,但未处理过的图得出来的结果却不是,可见这题是要把图处理一下的,我用了floyd,感觉O(n^3)是会TLE的,都是没有。
//1144K 969MS C++ 1024B 2014-06-14 09:27:31
#include<stdio.h>
#include<string.h>
#define N 505
int g[N][N];
int match[N];
int vis[N];
int n,m;
void floyd()
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(g[i][k] && g[k][j])
g[i][j]=;
}
int dfs(int u)
{
for(int i=;i<=n;i++)
if(!vis[i] && g[u][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=u;
return ;
}
}
return ;
}
int hungary()
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int a,b;
while(scanf("%d%d",&n,&m)!=EOF && (n+m))
{
memset(g,,sizeof(g));
for(int i=;i<m;i++){
scanf("%d%d",&a,&b);
g[a][b]=;
}
floyd();
printf("%d\n",n-hungary());
}
return ;
}
poj 2594 Treasure Exploration (二分匹配)的更多相关文章
- poj 2594 Treasure Exploration 二分图匹配
		点击打开链接题目链接 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7215 ... 
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
		POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ... 
- Poj 2594 Treasure Exploration (最小边覆盖+传递闭包)
		题目链接: Poj 2594 Treasure Exploration 题目描述: 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过 ... 
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
		http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ... 
- POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】
		Treasure Exploration Time Limit:6000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ... 
- POJ 2594	Treasure Exploration(带交叉路的最小路径覆盖)
		题意: 派机器人去火星寻宝,给出一个无环的有向图,机器人可以降落在任何一个点上,再沿着路去其他点探索,我们的任务是计算至少派多少机器人就可以访问到所有的点.有的点可以重复去. 输入数据: 首先是n和 ... 
- POJ 2594 Treasure Exploration 最小可相交路径覆盖
		最小路径覆盖 DAG的最小可相交路径覆盖: 算法:先用floyd求出原图的传递闭包,即如果a到b有路径,那么就加边a->b.然后就转化成了最小不相交路径覆盖问题. 这里解释一下floyd的作用如 ... 
- POJ 2594 Treasure Exploration (可相交最小路径覆盖)
		题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ... 
- poj 2594 Treasure Exploration(最小路径覆盖,可重点)
		题意:选出最小路径覆盖图中所有点,路径可以交叉,也就是允许路径有重复的点. 分析:这个题的难点在于如何解决有重复点的问题-方法就是使用Floyd求闭包,就是把间接相连的点直接连上边,然后就是求最小路径 ... 
随机推荐
- ubuntu下git安装及使用
			ubuntu下git安装及使用 其实,好几个月前,就已经安装好了,可是一直搁置在那儿,所以密码等一些其它细节都忘的差不多了,所以今天就重新部署了一下,并开始积极使用......... 1,git ... 
- Webpack 入门指南 - 3. Hello, Angular2!
			Webpack 入门指南 - 1.安装 Webpack 入门指南 - 2.模块 这一次,我们使用 Webpack 来打包 Angular 2 的应用. 与官方的 Hello, Angular 2 项目 ... 
- leetcode 191
			191. Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1' ... 
- UITableView的创建及其一些常用方法
			UITableView,它的数据源继承于UITableViewDataSource,它的委托UITableViewDelegate. 一.UITableView的创建 1.代码方式: UITableV ... 
- MySQL For Windows Zip解压版安装
			前言 Windows 下 MySQL 有msi和zip解压安装版两种,而zip版只需解压并做简单配置后就能使用,我个人比较喜欢这种方式. 注意我们这里说的MySQL是指MySQL服务器,有很多初学的同 ... 
- for..in遍历,枚举器
			#pragma mark ------------for循环遍历集合中的元素------ //创建一个数组,包含5个字符串对象,倒序取出数组中的所有元素,并存储到另一可变数组中 NSArray *ar ... 
- delphi FMX 数字下拉滑动
			滑动输入数字 NumberBox控件 HorzIncrement:划动自动增加输入值的步长 combobox控件 http://docwiki.embarcadero.com/RADStudio/Be ... 
- 学校系统快速js代码
			var select_arr=document.getElementById("iframeautoheight").contentWindow.document.getEleme ... 
- Winform DataGridView控件添加行号
			有很多种方法,这里介绍三种: A: 控件的RowStateChanged事件中添加,RowStateChanged事件是在行的状态更改(例如,失去或获得输入焦点)时发生的事件: e.Row.Hea ... 
- php后台权限管理
			今天新到一家公司,重新维护升级了之前的权限管理. 权限管理思路:1.三张表(公司项目比较复杂,所以数据表远比这个复杂,这里只实现权限管理,简化一下)action表------权限大菜单:这个表没有实际 ... 
