poj 2594 Treasure Exploration (二分匹配)
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 6558 | Accepted: 2644 |
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
最小路径覆盖(非最小边覆盖):
使用最少的边把所有点覆盖=原点数-最大匹配(修改后的图)
注意一种情况:
5 4
1-->3
2-->3
3-->4
3-->5
这里其实用2个robots就行了,但未处理过的图得出来的结果却不是,可见这题是要把图处理一下的,我用了floyd,感觉O(n^3)是会TLE的,都是没有。
//1144K 969MS C++ 1024B 2014-06-14 09:27:31
#include<stdio.h>
#include<string.h>
#define N 505
int g[N][N];
int match[N];
int vis[N];
int n,m;
void floyd()
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(g[i][k] && g[k][j])
g[i][j]=;
}
int dfs(int u)
{
for(int i=;i<=n;i++)
if(!vis[i] && g[u][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=u;
return ;
}
}
return ;
}
int hungary()
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int a,b;
while(scanf("%d%d",&n,&m)!=EOF && (n+m))
{
memset(g,,sizeof(g));
for(int i=;i<m;i++){
scanf("%d%d",&a,&b);
g[a][b]=;
}
floyd();
printf("%d\n",n-hungary());
}
return ;
}
poj 2594 Treasure Exploration (二分匹配)的更多相关文章
- poj 2594 Treasure Exploration 二分图匹配
点击打开链接题目链接 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7215 ...
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...
- Poj 2594 Treasure Exploration (最小边覆盖+传递闭包)
题目链接: Poj 2594 Treasure Exploration 题目描述: 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过 ...
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ...
- 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 最小可相交路径覆盖
最小路径覆盖 DAG的最小可相交路径覆盖: 算法:先用floyd求出原图的传递闭包,即如果a到b有路径,那么就加边a->b.然后就转化成了最小不相交路径覆盖问题. 这里解释一下floyd的作用如 ...
- POJ 2594 Treasure Exploration (可相交最小路径覆盖)
题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ...
- poj 2594 Treasure Exploration(最小路径覆盖,可重点)
题意:选出最小路径覆盖图中所有点,路径可以交叉,也就是允许路径有重复的点. 分析:这个题的难点在于如何解决有重复点的问题-方法就是使用Floyd求闭包,就是把间接相连的点直接连上边,然后就是求最小路径 ...
随机推荐
- PHP5.6.15连接Sql Server 2008配置方案
php5.6的如果想连接Sql Server 2008数据库,需要手动配置扩展和安装一个驱动. 下载SQL Server Driver for PHP的扩展包,64位系统的官方不支持,找到一个非官方的 ...
- 环境搭建 Hadoop+Hive(orcfile格式)+Presto实现大数据存储查询一
一.前言 Hadoop简介 Hadoop就是一个实现了Google云计算系统的开源系统,包括并行计算模型Map/Reduce,分布式文件系统HDFS,以及分布式数据库Hbase,同时Hadoop的相关 ...
- Linux:cacti环境部署
一.监控端安装1)基础软件:安装配置cacti前,需要安装:httpd.php.mysqld.php-mysql.net-snmp.rrdtool以上均可使用yum安装:yum install -y ...
- 解决linux yum无法安装mysql
yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 wget http://repo.mysql.com/mysql-com ...
- nslookup命令
nslookup命令可以从本地DNS服务器中查看所有的IP地址和域名信息(它就像一本互联网电话簿).例如,想要找到www.baidu.com的IP地址就可以使用nslookup命令. nslookup ...
- etc 安装及使用
键值存储仓库,用于配置共享和服务发现. A highly-available key value store for shared configuration and service discover ...
- dubbo-monitor图标功能不显示
原因有3: 1.需要创建目录 2.需要在consumer的配置文件中增加如下配置,使用zk为注册中心 <!-- 监控中心,需要配置以后dubbo-monitor才能生效 --> &l ...
- LB负载均衡层次结构(摘抄)
作为后端应用的开发者,我们经常开发.调试.测试完我们的应用并发布到生产环境,用户就可以直接访问到我们的应用了.但对于互联网应用,在你的应用和用户之间还隔着一层低调的或厚或薄的负载均衡层软件,它们不显山 ...
- MongoDB是一个介于关系数据库和非关系数据库之间的产品
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型.M ...
- Haproxy日志配置
haproxy在默认情况不会记录日志,除了在haproxy.conf中的global段指定日志的输出外,还需要配置系统日志的配置文件.下面以centos6.4为例,haproxy使用系统自带的rpm报 ...