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 ...
随机推荐
- Python14__网络SOCKET
- const int* p
若纠结于const int* p,int const* p,int* const p这三个指针,可以看视频 https://www.icourse163.org/learn/BUPT-10035640 ...
- 046_Shell 脚本的 fork 炸弹
#!/bin/bash#快速消耗计算机资源,致使计算机死机#定义函数名为.(点), 函数中递归调用自己并放入后台执行.() {.|.& };.
- windows日志分析工具-LogonTracer
0x01 Windows应急日志常用的几个事件ID 4624:这个事件ID表示成功登陆的用户,用来筛选该系统的用户登陆成功情况. 4625:这个事件ID表示登陆失败的用户. 4768:这个事件ID表示 ...
- Codevs 1743 反转卡片(splay)
1743 反转卡片 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description [dzy493941464|yywyzdzr原创] 小A将N ...
- mfc编程之发送wm_paint消息时绘图界面只出现一瞬间
实现的功能是在打开一个文件然后把文件的图形信息绘制在picture控件上. 问题描述:我把绘制的操作放在了窗口中onpaint()函数里,打开文件后发送一个wm_paint的消息,发现picture控 ...
- 页面ajax请求传参及java后端数据接收
js ajax请求传参及java后端数据接收 Controller: package com.ysl.PassingParameters.controller; import java.util.Li ...
- 【零基础】风格迁移之deep-painterly-harmonization的安装和使用
注:原项目名叫deep-painterly-harmonization,这里我缩写下称呼其为“DPH” 注:原项目GIT链接:https://github.com/luanfujun/deep-pai ...
- 2018-2019-2 20165210《网络对抗技术》Exp7 网络欺诈防范
2018-2019-2 20165210<网络对抗技术>Exp7 网络欺诈防范 一.实验目标:本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法. 二.实验内容: ...
- 区间dp括号匹配
POJ2955 匹配则加一,不需要初始化 //#include<bits/stdc++.h> #include<iostream> #include<cstdio> ...