hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7469 | Accepted: 4451 |
Description
With these assumptions your task is to write a program that finds the minimum number of paratroopers that can descend on the town and visit all the intersections of this town in such a way that more than one paratrooper visits no intersection. Each paratrooper lands at an intersection and can visit other intersections following the town streets. There are no restrictions about the starting intersection for each paratrooper.
Input
no_of_intersections
no_of_streets
S1 E1
S2 E2
......
Sno_of_streets Eno_of_streets
The first line of each data set contains a positive integer no_of_intersections (greater than 0 and less or equal to 120), which is the number of intersections in the town. The second line contains a positive integer no_of_streets, which is the number of streets in the town. The next no_of_streets lines, one for each street in the town, are randomly ordered and represent the town's streets. The line corresponding to street k (k <= no_of_streets) consists of two positive integers, separated by one blank: Sk (1 <= Sk <= no_of_intersections) - the number of the intersection that is the start of the street, and Ek (1 <= Ek <= no_of_intersections) - the number of the intersection that is the end of the street. Intersections are represented by integers from 1 to no_of_intersections.
There are no blank lines between consecutive sets of data. Input data are correct.
Output
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
Sample Output
2
1 最小路径覆盖 = 总点数 - 最大匹配数
最小路径覆盖:
用最少的路径覆盖所有点(把有向图转化为二分图+无向边):
(前提是没有环的有向图)转化为二分图后既为无向边,从左边点到右边点表示了方向。
最终找到的匹配边对,代表了右边的点可以由其他未被选中的右边序号的点所到达,
因此,用总点数-匹配的对数 = 需要作为出发的点数。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define N 310
#define INF 0x3f3f3f3f using namespace std; int G[N][N], vis[N], used[N];
int n; bool Find(int u)
{
int i;
for(i = ; i <= n ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} int main()
{
int m, i, a, b, t, ans;
scanf("%d", &t);
while(t--)
{
ans = ;
memset(G, , sizeof(G));
scanf("%d%d", &n, &m);
while(m--)
{
scanf("%d%d", &a, &b);
G[a][b] = ;
}
memset(used, , sizeof(used));
for(i = ; i <= n ; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", n - ans);
}
return ;
}
hdu 1151 Air Raid(二分图最小路径覆盖)的更多相关文章
- HDU 1151 Air Raid(最小路径覆盖)
题目大意: 有n个城市,m条道路,城市的道路是单向. 现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...
- HDU - 1151 Air Raid (最小路径覆盖)
题意:给定一个有向无环图,求最少划分几条路径,使之能够覆盖所有点. 分析:这可以转化为DAG上的最小路径覆盖问题. 路径覆盖的定义:有向图中,路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且 ...
- hdu 1151 Air Raid DAG最小边覆盖 最大二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少 ...
- Air Raid(最小路径覆盖)
Description Consider a town where all the streets are one-way and each street leads from one interse ...
- HDU 6311 Cover (无向图最小路径覆盖)
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- [bzoj2150]部落战争_二分图最小路径覆盖
部落战争 bzoj-2150 题目大意:题目链接. 注释:略. 想法: 显然是最小路径覆盖,我们知道:二分图最小路径覆盖等于节点总数-最大匹配. 所以我们用匈牙利或者dinic跑出最大匹配,然后用总结 ...
- Taxi Cab Scheme POJ - 2060 二分图最小路径覆盖
Running a taxi station is not all that simple. Apart from the obvious demand for a centralised coord ...
- hdu - 1151 Air Raid(有向无环图的最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 在一个城市里有n个地点和k条道路,道路都是单向的,并且不存在环.(DAG) 现在伞兵需要去n个地点视察,伞 ...
- (step6.3.4)hdu 1151(Air Raid——最小路径覆盖)
题意: 一个镇里所有的路都是单向路且不会组成回路. 派一些伞兵去那个镇里,要到达所有的路口,有一些或者没有伞兵可以不去那些路口,只要其他人能完成这个任务.每个在一个路口着陆了的伞兵可以沿着街去 ...
随机推荐
- BZOJ 3132 上帝造题的七分钟(二维树状数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3132 题意:给出一个矩阵,两种操作:(1)将某个子矩阵的数字统一加上某个值:(2)查询某 ...
- [58 Argo]58同城开源web框架Argo搭建实践
无意间听说58开源的消息(Long long ago),我辈欣喜异常. 一方面感谢开源同仁的辛苦劳动,另一方面也为我辈在互联网技术实践圈外的人提供了一条实践的渠道. 我迫不及待的从github上dow ...
- POJ 2947 Widget Factory (高斯消元 判多解 无解 和解集 模7情况)
题目链接 题意: 公司被吞并,老员工几乎全部被炒鱿鱼.一共有n种不同的工具,编号1-N(代码中是0—N-1), 每种工具的加工时间为3—9天 ,但是现在老员工不在我们不知道每种工具的加工时间,庆幸的是 ...
- bzoj3955
首先,最短路不同的两辆车一定不会发生堵塞 对于最短路相同的点,我们把属于最短路径上的边拎出来建图跑最大流即可 然后我TLE了…… 因为很明显建出来图很大,而真正流的流量很小 普通的初始标号都是0的sa ...
- Nodejs express中创建ejs项目 error install Couldn't read dependencies
最近在看<Node.js开发指南>,看到使用nodejs进行web开发的时候,准备创建ejs项目遇到问题了 书上命令为: express -t ejs microblog 可是执行 ...
- sharepoint Linq方式的增,删,查,改
Site9527EntitiesDataContext (重要的类):连接实体与网站List操作 SPContext.Current.Web.Url:获取当前操作的页面 FirstOrDefault: ...
- 【Struts】服务器文件的上传和下载
Java中获得文件的文件后缀 import java.io.*; public class FileTest{ public static void main(String args[]){ File ...
- 【转】win7(windows7)下java环境变量配置方法
原文网址:http://jingyan.baidu.com/article/925f8cb836b26ac0dde0569e.html win7(windows7)下java环境变量配置方法,java ...
- date.plugin.js 日期插件
//定义命名空间 var DatePlugin; if (!DatePlugin) DatePlugin = {}; /*整理时间:2015-05-28*/ var defaultFormat = & ...
- Log4NET简介
log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具. 前提 最近做项目需要记录系统日志和用 ...