poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594
| Time Limit: 6000MS | Memory Limit: 65536K | |
| Total Submissions: 7398 | Accepted: 3025 | 
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 一开始看到这道题以为就是简单的最小路径问题,直接套用最模版提交了,没想到wa了,仔细一看发现自己把题想简单了,还是没有彻底理解概念
题中有句话还是蛮重要的(已经用红色标出来了),多个士兵可以经过相同的一个点 如:1->3,2->3,3->4,3->5, 如果用平常的最小路径来写顶点最多只经过一次,结果就是;而这道题顶点可以经过多次,结果应该是2,两个士
兵都可以经过点3 那么如何来构造普通最小路径的二分图呢 如果上例,1 和 2 都经过点3 分别到达 4 和 5 ,那么就让 1 和 2 不通过 点3 直接到达 4 和 5,用Floyd来构造二分图使之可以用普通的
最小路径覆盖来写
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define N 510
#define INF 0x3f3f3f3f using namespace std; int G[N][N], vis[N], used[N];
int m, n; bool Find(int u)
{
int i;
for(i = ; i <= n ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} void Floyd()
{
int i, j, k;
for(k = ; k <= n ; k++)
{
for(i = ; i <= n ; i++)
{
for(j = ; j <= n ; j++)
{
if(G[i][k] && G[k][j])
G[i][j] = ;
}
}
}
}//求传递闭包并构建新的二分图 int main()
{
int i, a, b;
while(scanf("%d%d", &n, &m), m + n)
{
memset(G, , sizeof(G));
while(m--)
{
scanf("%d%d", &a, &b);
G[a][b] = ;
}
Floyd();
memset(used, , sizeof(used));
int ans = ;
for(i = ; i <= n ; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", n - ans);
}
return ;
}
poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)的更多相关文章
- Poj 2594 Treasure Exploration (最小边覆盖+传递闭包)
		
题目链接: Poj 2594 Treasure Exploration 题目描述: 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过 ...
 - K - Treasure Exploration - POJ 2594(最小路径覆盖+闭包传递)
		
题意:给一个有向无环图,求出来最小路径覆盖,注意一个点可能会被多条路径重复 分析:因为有可能多条路径走一个点,可又能会造成匹配的不完全,所以先进行一次闭包传递(floyd),然后再用二分匹配的方法求出 ...
 - POJ 2594 传递闭包的最小路径覆盖
		
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7171 Accepted: 2 ...
 - POJ 2594 (传递闭包 + 最小路径覆盖)
		
题目链接: POJ 2594 题目大意:给你 1~N 个点, M 条有向边.问你最少需要多少个机器人,让它们走完所有节点,不同的机器人可以走过同样的一条路,图保证为 DAG. 很明显是 最小可相交路径 ...
 - POJ 2594 Treasure Exploration(最小路径覆盖变形)
		
POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...
 - 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(最小路径覆盖,可重点)
		
题意:选出最小路径覆盖图中所有点,路径可以交叉,也就是允许路径有重复的点. 分析:这个题的难点在于如何解决有重复点的问题-方法就是使用Floyd求闭包,就是把间接相连的点直接连上边,然后就是求最小路径 ...
 - POJ 2594 Treasure Exploration (可相交最小路径覆盖)
		
题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ...
 
随机推荐
- 查找所有含有表名(abc)的存储过程 执行脚本
			
SELECT obj.Name , sc.TEXT FROM syscomments sc INNER JOIN sysobjects obj ON sc.Id = obj.ID WHERE sc.T ...
 - UVa 1609 (博弈) Foul Play
			
姑且把它归类为一道博弈吧,毕竟这也是在找必胜方案. 十分有意思的一道题目,设计一种方案让你支持的1队获胜. 题目给出了两个很重要的条件: 1队能打败至少一半的队伍 对于1队不能打败的黑队,一定存在一个 ...
 - 51nod1678 lyk与gcd
			
容斥定理所以可以用莫比乌斯函数来搞.逆向思维答案等于总和减去和他互质的.那么设f[i]=∑a[j] i|j.ans[i]=sum- ∑mo[j]*f[j] 跟bzoj2440那道题挺像的都是利用莫比乌 ...
 - 多个MapReduce作业相互依赖时,使用JobControl进行管理
			
要处理复杂关系的数据,一个工程里面绝对不止一个MapReduce作业,当有多个MapReduce作业时, 并且每个作业之间有依赖关系,所谓的依赖就是一个作业得到的结果是另外一个作业的输入, ...
 - BZOJ 4636 蒟蒻的数列
			
二分写错了血T..... 线段树标记永久化. #include<iostream> #include<cstdio> #include<cstring> #incl ...
 - 移植yaffs文件系统
			
需要下载yaffs2-d43e901.tar.gz,busybox-1.13.0.tar.bz2 使用的交叉编译器是4.33 1.修改配置编译busybox 修改Makefile CROSS_COMP ...
 - myisam 与innodb的区别
			
myisam 与innodb的区别 frm结构 fri索引 frd数据 innodb:一个表一个文件:frm文件 所有的innodb表,都使用表空间储存, 数据和索引的保存文件不同,myisam 分开 ...
 - Heritrix源码分析(九) Heritrix的二次抓取以及如何让Heritrix抓取你不想抓取的URL
			
本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/644396 本博客已迁移到本人独立博客: http://www.yun5u ...
 - 一天一点MySQL复习——获取数据库系统时间、变量赋值、变量比较
			
一.SQL获取系统时间 mysql> select now() from dual; +---------------------+ | now() | +------------------- ...
 - 大数据时代的技术hive:hive介绍
			
我最近研究了hive的相关技术,有点心得,这里和大家分享下. 首先我们要知道hive到底是做什么的.下面这几段文字很好的描述了hive的特性: 1.hive是基于Hadoop的一个数据仓库工具,可以将 ...