poj2594:Treasure Exploration
来源:互联网 发布:渭南网络电视台 编辑:程序博客网 时间:2024/04/30 01:00
2594:Treasure Exploration
- 总时间限制:
- 6000ms
- 内存限制:
- 65536kB
- 描述
- Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you ever explored treasure? If you never have such experiences, you would never know what fun treasure exploring brings to you.
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? - 输入
- The input will consist of several test cases. For each test case, two integers N (1 <= N <= 500) and M (0 <= M <= 5000) are given in the first line, indicating the number of points and the number of one-way roads in the graph respectively. Each of the following M lines contains two different integers A and B, indicating there is a one-way from A to B (0 < A, B <= N). The input is terminated by a single line with two zeros.
- 输出
- For each test of the input, print a line containing the least robots needed.
- 样例输入
1 02 11 22 00 0
- 样例输出
112
大致题意: 给出一个由n个顶点m条边组成的无回路有向图。求最少可以同时存在多少路径,使得这些路径可以覆盖所有的点(注:每个都点可以被多条路径覆盖)。大致思路: 最小路径覆盖的一点小小变形,由于这里的点可以被重复覆盖,所以除了按照普通求最小路径覆盖的方式建立二分图以外,还要对原图用floyd求一遍传递闭包,并更新二分图。接下来用点数n减去最大匹配得到的就是答案。#include<stdio.h>#include<string.h>#define N 1010int map[N][N],mode[N],vis[N];int n,m;void floyd()// 用floyd求一遍传递闭包,并更新二分图。{int i,j,k;for(k=1;k<=n;k++){for(j=1;j<=n;j++){for(i=1;i<=n;i++){if(map[i][k]&&map[k][j])map[i][j]=1;}}} } int find(int x)//寻找增广路! 找到返回1,否则返回0!{int i,j;for(i=1;i<=n;i++){ if(map[x][i]&&!vis[i]) { vis[i]=1; if(!mode[i]||find(mode[i]))//i 点 没有和另一部分匹配或 和i配对的点 没有匹配! { mode[i]=x; return 1; } }}return 0;}int main(){int i,j;while(scanf("%d%d",&n,&m)&&(n||m)){int x,y;memset(map,0,sizeof(map));memset(mode,0,sizeof(mode));for(i=1;i<=m;i++){scanf("%d%d",&x,&y);if(x&&y)map[x][y]=1;}floyd();int s=0;for(i=1;i<=n;i++){memset(vis,0,sizeof(vis));if(find(i))//增广路 s++;}printf("%d\n",n-s);}return 0;}
0 0
- poj2594 Treasure Exploration
- POJ2594-Treasure Exploration
- poj2594:Treasure Exploration
- poj2594 treasure exploration
- POJ2594-Treasure Exploration
- 【POJ2594】Treasure Exploration 宝藏勘探
- POJ2594-Treasure Exploration(最小路径覆盖变形)
- poj2594 Treasure Exploration(二分图)
- POJ2594 Treasure Exploration(最小路径覆盖)
- poj2594 Treasure Exploration【最小路径覆盖】
- POJ2594 Treasure Exploration 最小点覆盖题目[有重复点]
- POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
- 可重叠的最小路径覆盖 poj2594 Treasure Exploration
- 【POJ2594】Treasure Exploration 宝藏勘探 二分图最大匹配
- poj2594 Treasure Exploration(可相交最小路径覆盖)
- poj2594 Treasure Exploration 最小路径覆盖=顶点数-最大匹配数
- poj2594——Treasure Exploration(闭包+最小路径覆盖)
- poj2594-Treasure Exploration(最小路径覆盖,最大匹配,floyed(优化))
- “米粉节”背后的故事——小米网抢购系统开发实践
- android:src
- CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?
- java 猜数字小游戏
- POJ 2686 Traveling by Stagecoach
- poj2594:Treasure Exploration
- c++迭代器详解(一):back_inserter, front_inserter,inserter
- 单链表(七)——判断两链表是否交叉
- 斯坦福Developing iOS 8 Apps学习笔记(四)
- linux 安装flash
- 《剑指offer》求1+2+3+...+n
- Eclipse关联java源代码
- 【软考视频基础知识】——数据结构
- PS CS6中如何制作简易GIF动画图片