POJ 2594 传递闭包的最小路径覆盖
| Time Limit: 6000MS | Memory Limit: 65536K | |
| Total Submissions: 7171 | Accepted: 2930 |
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
给一个无环的有向图,求最少多少条路径能把所有点覆盖,其中点是可以重复覆盖的。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 505 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int from[N];
bool visited[N];
int n, m;
int map[N][N]; int march(int u){
int i, v;
for(v=;v<=n;v++){
if(!visited[v]&&map[u][v]){
visited[v]=true;
if(from[v]==-||march(from[v])){
from[v]=u;
return ;
}
}
}
return ;
} main()
{
int i, j, k, u, v;
while(scanf("%d %d",&n,&m)==){
if(n==&&m==) break;
memset(map,,sizeof(map));
for(i=;i<m;i++){
scanf("%d %d",&u,&v);
map[u][v]=;
}
for(i=;i<=n;i++){
for(j=;j<=n;j++){
for(k=;k<=n;k++){
if(map[i][j]&&map[j][k]&&!map[i][k]) map[i][k]=;
}
}
}
int num=;
memset(from,-,sizeof(from));
for(i=;i<=n;i++){
memset(visited,false,sizeof(visited));
if(march(i)) num++;
}
printf("%d\n",n-num);
}
}
POJ 2594 传递闭包的最小路径覆盖的更多相关文章
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ...
- Treasure Exploration---poj2594(传递闭包Floyd+最小路径覆盖)
题目链接:http://poj.org/problem?id=2594 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过(这就是和单 ...
- poj 3020 Antenna Placement (最小路径覆盖)
链接:poj 3020 题意:一个矩形中,有n个城市'*'.'o'表示空地,如今这n个城市都要覆盖无线,若放置一个基站, 那么它至多能够覆盖本身和相邻的一个城市,求至少放置多少个基站才干使得全部的城市 ...
- POJ 1548 Robots(最小路径覆盖)
POJ 1548 Robots 题目链接 题意:乍一看还以为是小白上那题dp,事实上不是,就是求一共几个机器人能够覆盖全部路径 思路:最小路径覆盖问题.一个点假设在还有一个点右下方,就建边.然后跑最小 ...
- POJ 1422 二分图(最小路径覆盖)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7278 Accepted: 4318 Descript ...
- POJ 1422 Air Raid (最小路径覆盖)
题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...
- POJ 1548 (二分图+最小路径覆盖)
题目链接:http://poj.org/problem?id=1548 题目大意:给出一张地图上的垃圾,以及一堆机器人.每个机器人可以从左->右,上->下.走完就废.问最少派出多少个机器人 ...
- POJ_2594_最小路径覆盖
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8085 Accepted: 3 ...
- POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】
Treasure Exploration Time Limit:6000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- NSDate使用
//获取当前日期,时间 +(NSDate *)getCurrentDate{ NSDate *now = [NSDate date]; return now; } //将日期转换为字符 ...
- poj3449Geometric Shapes
链接 繁琐. 处理出来所有的线段,再判断相交. 对于正方形的已知对角顶点求剩余两顶点 (列出4个方程求解) p[].x=(p[].x+p[].x+p[].y-p[].y)/; p[].y=(p[].y ...
- jprofiler安装图解及破解码
原文:http://blog.csdn.net/lifuxiangcaohui/article/details/38677889 环境: 1.sun jdk1.6.0 2.jprofiler_wind ...
- Android控件之CheckBox(复选框控件)
一.有两种状态: 选中状态(true).未选中状态(false) 二.属性 android:id = "@+id/checkbox" android:layout_width=&q ...
- 出现 could not open jvm.cfg 的解决办法
出现该的原因很可能是由于卸载 jdk 不干净而引起的(就算是使用工具也一样),在oracle的官方上也是让我们卸载了重装一次.可是重装真的能解决问题吗? 以下方法经过本人的验证,绝对可行! (一定要 ...
- vs2010工程迁移问题,x64到Win32
ALL_BUILD:vcxproj:找不到项目文件“ALL_BUILD”中引用的平台“x64”.请确保已将该平台安装在“%VCTargetsPath%\Platforms\x64”下.无法加载项目. ...
- 犯过错误的C语言问题
1 memcpy函数: 函数原型:void *memcpy(void *dest, void *src, unsigned int count); 函数源码: void *memcpy1(void * ...
- 美国半个互联网瘫痪对开发者使用DNS的启发
版权声明:本文由腾讯云DNSPod团队原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/174 来源:腾云阁 https:// ...
- sublime2配置python环境
只需要在以下文件写入python编译器的路径: 在工具栏点击Preferences,打开Browse Packages.在打开的文件夹中找到Python,并打开这个文件夹.找到文件Python.sub ...
- noip赛前小结3
嗯,这是第三份小结. 连续三天的小结. 这几天状态逐渐回来了. 前天3道题rk8左右. 昨天上午3道题rk7,但是有一道题考后1minAC了. 昨天晚上2道题AK了. 今天也3道题rk1了. 这个趋势 ...