Treasure Exploration---poj2594(传递闭包Floyd+最小路径覆盖)
题目链接:http://poj.org/problem?id=2594
在外星上有n个点需要机器人去探险,有m条单向路径。问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过(这就是和单纯的最小路径覆盖的区别)。
因为图是一个有向图
例如 1—>3,
2—>3;
3—>4;
3—>5;
左边是floyd之前的,右边是传递之后的,左边的最大匹配是2,右边是3;
其中为什么用传递闭包就能求最大匹配,自己只可意会不可言传;—_—;
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
#define N 510
int vis[N], used[N], maps[N][N], n, ans; void floyd()
{
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(maps[i][k] && maps[k][j])
maps[i][j] = ;
} bool Find(int u)
{
for(int i=; i<=n; i++)
{
if(!vis[i] && maps[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
}
int main()
{
int a, b, m;
while(scanf("%d%d", &n, &m), m+n)
{
memset(maps, , sizeof(maps));
for(int i=; i<m; i++)
{
scanf("%d%d", &a, &b);
maps[a][b] = ;
}
floyd();
ans = ;
memset(used, , sizeof(used));
for(int i=; i<=n; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", n - ans);
}
return ;
}
Treasure Exploration---poj2594(传递闭包Floyd+最小路径覆盖)的更多相关文章
- POJ Treasure Exploration 【DAG交叉最小路径覆盖】
传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K To ...
- K - Treasure Exploration - POJ 2594(最小路径覆盖+闭包传递)
题意:给一个有向无环图,求出来最小路径覆盖,注意一个点可能会被多条路径重复 分析:因为有可能多条路径走一个点,可又能会造成匹配的不完全,所以先进行一次闭包传递(floyd),然后再用二分匹配的方法求出 ...
- POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 9794 Accepted: 3 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)
<题目链接> 题目大意: 机器人探索宝藏,有N个点,M条边.问你要几个机器人才能遍历所有的点. 解题分析: 刚开始还以为是最小路径覆盖的模板题,但是后面才知道,本题允许一个点经过多次,这与 ...
- POJ 2594 传递闭包的最小路径覆盖
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7171 Accepted: 2 ...
- HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
- hdu 4606 简单计算几何+floyd+最小路径覆盖
思路:将所有的直线的两个端点和城市混在一起,将能直接到达的两个点连线,求一次floyd最短路径.二分枚举bag容量,然后按给的要先后占领的城市由前向后,把能到一步到达的建一条边.然后求一次最小路径覆盖 ...
- poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)
http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Su ...
随机推荐
- testNG框架提示:Cannot find class in classpath: NewTest
selenium+Java的testNG运行时,报如下错误: org.testng.TestNGException: Cannot find class in classpath: NewTest a ...
- hadoop程序MapReduce之average
需求:求多门课程的平均值. 样板:math.txt zhangsan 90 lisi 88 wanghua 80 china.txt zhangsan 80lisi 90wanghua 88 输出:z ...
- UE4 Run On Server与Run on owning client
- NSData 方法
/****************Immutable Data****************/ @interface NSData : NSObject <NSCopying, NSMutab ...
- 《C++ Primer Plus》14.4 类模板 学习笔记
14.4.1 定义类模板下面以第10章的Stack类为基础来建立模板.原来的类声明如下:typedef unsigned long Item; class Stack{private: enum ...
- nil、Nil、NULL与NSNull的区别及应用
总结 nil:OC中的对象的空指针 Nil:OC中类的空指针 NULL:C类型的空指针 NSNull:数值类的空对象 详细解析应用如下: 1.nil 指向一个对象的指针为空 在objc.h中的定义 ...
- iOS-代码修改Info.plist文件
解决办法: 1.首先系统的Info.Plist文件是只读文件 并不能 写入.目前我个人是没有办法存入,官方属性 可以看到是readOnly 2.那么我们 就想代码修改Info.Plist文件怎么办呢, ...
- php面向对象的简单总结 $this $parent self
面向对象涉及到的比较多,大概总结整理一下php的属性.对象,以及访问方式$this $parent self 的使用场景. 1. PHP类属性定义和访问方式: 1 <?php 2 clas ...
- Linux命令行常用光标移动快捷键
Linux 命令行快捷键 涉及在Linux命令行下进行快速移动光标.命令编辑.编辑后执行历史命令.Bang(!)命令.控制命令等.让basher更有效率. 常用 ctrl+左右键:在单词之间跳转 ct ...
- 【Spring Boot && Spring Cloud系列】构建Springboot项目 实现restful风格接口
项目代码如下: package hello; import org.springframework.boot.SpringApplication; import org.springframework ...