POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】
题目链接:http://poj.org/problem?id=2594
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions:10480 | Accepted: 4250 |
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
#include<stdio.h>
#include<string.h>
#define mem(a, b) memset(a, b, sizeof(a))
const int MAXN = ;
const int MAXM = ; int n, m; //n个点 m条有向边
int line[MAXN][MAXN], used[MAXN], master[MAXN]; void floyd()
{
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
for(int k = ; k <= n; k ++)
if(line[i][k] && line[k][j])
line[i][j] = ;
} int find(int x)
{
for(int i = ; i <= n; i ++) //y部的点
{
if(line[x][i] && used[i] == -)
{
used[i] = ;
if(master[i] == - || find(master[i]))
{
master[i] = x;
return ;
}
}
}
return ;
} int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
if(n == && m == )
break;
int cnt = ;
mem(line, ), mem(master, -);
for(int i = ; i <= m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
line[a][b] = ;
}
floyd();
for(int i = ; i <= n; i ++) //x部的点
{
mem(used, -);
if(find(i))
cnt ++; //最大匹配数
}
printf("%d\n", n - cnt);
}
return ;
}
POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】的更多相关文章
- POJ 2594 Treasure Exploration(带交叉路的最小路径覆盖)
题意: 派机器人去火星寻宝,给出一个无环的有向图,机器人可以降落在任何一个点上,再沿着路去其他点探索,我们的任务是计算至少派多少机器人就可以访问到所有的点.有的点可以重复去. 输入数据: 首先是n和 ...
- loj 1429(可相交的最小路径覆盖)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1429 思路:这道题还是比较麻烦的,对于求有向图的可相交的最小路径覆盖,首先要解决成环问 ...
- POJ2594 Treasure Exploration[DAG的最小可相交路径覆盖]
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8301 Accepted: 3 ...
- Treasure Exploration POJ - 2594 【有向图路径可相交的最小路径覆盖】模板题
Have you ever read any book about treasure exploration? Have you ever see any film about treasure ex ...
- poj 2594(可相交的最小路径覆盖)
题目链接:http://poj.org/problem?id=2594 思路:本来求最小路径覆盖是不能相交的,那么对于那些本来就可达的点怎么处理,我们可以求一次传递闭包,相当于是加边,这样我们就可以来 ...
- poj 2594Treasure Exploration(有向图路径可相交的最小路径覆盖)
1 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> ...
- HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
- 【LA3126 训练指南】出租车 【DAG最小路径覆盖】
题意 你在一座城市里负责一个大型活动的接待工作.明天将有m位客人从城市的不同的位置出发,到达他们各自的目的地.已知每个人的出发时间,出发地点和目的地.你的任务是用尽量少的出租车送他们,使得每次出租车接 ...
- Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配
/** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...
随机推荐
- Maven+Docker 部署
Maven+Docker 部署 安装jdk8镜像 docker pull openjdk:8-jdk-alpine maven插件推送方式 修改/etc/docker/daemon.json文件,加入 ...
- 007_linuxC++之_构造函数的初级应用
(一)构造函数:用来在创建对象时初始化对象, 即为对象成员变量赋初始值 (二)构造函数的命名必须和类名完全相同 (三)更对具体的查看:构造函数 (四)直接分析程序 运行结果 解析上面程序: 1. 当程 ...
- redis数据存储--C++连接redis
一.下载的是Redis Windows版本:下载地址:https://github.com/microsoftarchive/redis:解压到:E:\Software\redis-3.0: 二.用V ...
- C到汇编[1]
这篇文字解释这个问题:C语言函数调用在汇编语言是怎么实现的?栈模型很好的满足了函数调用的需求,以最简单的函数调用说明. : int add2(int a, int b){return a+b;} 00 ...
- 提交项目到Github
create a new repository on the command line git init git add README.md git commit -m "first com ...
- 1656:Combination
一本通1656:Combination 1656:Combination 时间限制: 1000 ms 内存限制: 524288 KB提交数: 89 通过数: 49 [题目描述] ...
- speech-to-text-wavenet
docker pull buriburisuri/speech-to-text-wavenet docker run -it buriburisuri/speech-to-text-wavenet p ...
- layer 漂亮的弹窗
layer.confirm('<font color="red">请认真核对账目信息,提交后将不可撤回!!</font>', { icon:3, title ...
- 5.4.1 sequenceFile读写文件、记录边界、同步点、压缩排序、格式
5.4.1 sequenceFile读写文件.记录边界.同步点.压缩排序.格式 HDFS和MapReduce是针对大文件优化的存储文本记录,不适合二进制类型的数据.SequenceFile作 ...
- elasticsearch java动态设置mapping并指定分词器
//创建索引 client.admin().indices().prepareCreate("twitter").execute().actionGet(); //配置mappin ...