HDOJ 1151 Air Raid
最小点覆盖
Air Raid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3002 Accepted Submission(s): 1951
form no cycles.
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.
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.
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
2
1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn=220; bool mp[maxn][maxn],used[maxn];
int linker[maxn],n,m; bool dfs(int u)
{
for(int i=1;i<=n;i++)
{
if(used[i]) continue;
if(mp[u][i])
{
used[i]=true;
if(linker[i]==-1||dfs(linker[i])==true)
{
linker[i]=u;
return true;
}
}
}
return false;
} int hungary()
{
int ret=0;
memset(linker,-1,sizeof(linker));
for(int i=1;i<=n;i++)
{
memset(used,false,sizeof(used));
if(dfs(i)) ret++;
}
return ret;
} int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d%d",&n,&m);
memset(mp,false,sizeof(mp));
for(int i=0;i<m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
mp[a][b]=true;
}
printf("%d\n",n-hungary());
}
return 0;
}
HDOJ 1151 Air Raid的更多相关文章
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
- hdu 1151 Air Raid DAG最小边覆盖 最大二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少 ...
- hdu 1151 Air Raid - 二分匹配
Consider a town where all the streets are one-way and each street leads from one intersection to ano ...
- hdu - 1151 Air Raid(有向无环图的最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 在一个城市里有n个地点和k条道路,道路都是单向的,并且不存在环.(DAG) 现在伞兵需要去n个地点视察,伞 ...
- (step6.3.4)hdu 1151(Air Raid——最小路径覆盖)
题意: 一个镇里所有的路都是单向路且不会组成回路. 派一些伞兵去那个镇里,要到达所有的路口,有一些或者没有伞兵可以不去那些路口,只要其他人能完成这个任务.每个在一个路口着陆了的伞兵可以沿着街去 ...
- HDU 1151 Air Raid(最小路径覆盖)
题目大意: 有n个城市,m条道路,城市的道路是单向. 现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...
- HDU 1151 - Air Raid
很明显求最小路径覆盖 就是求最大匹配 #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- hdu 1151 Air Raid 最小路径覆盖
题意:一个城镇有n个路口,m条路.每条路单向,且路无环.现在派遣伞兵去巡逻所有路口,伞兵只能沿着路走,且每个伞兵经过的路口不重合.求最少派遣的伞兵数量. 建图之后的就转化成邮箱无环图的最小路径覆盖问题 ...
随机推荐
- 分析一下FastDFS_java_client中TestClient.java这个文件以及跟它关联的这条线
本来先打算上个图来说明一下这条线的,可是我的画图工具还没有安装好,我先把跟TestClient.java相关的几个文件代码贴上来,但是由于代码行数还是不少的,所以请大家阅读文章的时候先不要展开代码,等 ...
- jrtplib跨网络通讯NAT穿透问题解决方法
前几篇文章讲了使用jrtplib在Android和pc端进行通讯的方法 在实际项目中,手机端和pc端一般不会在同一个子网内,两者之间联络可能要走路由器之类的NAT(网络地址转换 Network Add ...
- .NET/ASP.NET Routing路由(深入解析路由系统架构原理)http://wangqingpei557.blog.51cto.com/1009349/1312422
阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模型的入口 4.ASP.NET Routing 路由对象模型的内部结构 4 ...
- SharePoint 2010 列表项事件接收器 ItemAdded 的使用方法
列表项事件处理器是继承于Microsoft.SharePoint.SPItemEventReceiver的类,Microsoft.SharePoint.SPItemEventReceiver类提供了许 ...
- Listview异步加载之优化篇
异步加载图片基本思想: 1. 先从内存缓存中获取图片显示(内存缓冲) 2. 获取不到的话从SD卡里获取(SD卡缓冲) 3. 都获取不到的话从网络下载图片并保存到SD卡同时 ...
- A标记点击后去掉虚线
没加时,谷歌无虚线,但ie有虚线. 加上这句,所有的a标签点击都没有虚线了. a {outline: none;} a:active {star:expression_r(this.onFocus=t ...
- Linux--使用expect进行自动交互
在linux下进行一些操作时,有时需要与机器进行一些交互操作,比如切换账号时输入账号密码,传输文件时输入账号密码登陆远程机器等,但有时候这些动作需要在shell脚本中进行,这个时候就可以使用expec ...
- SQL遍历字符串的方法
字符串穿越: 1.创建一个只存递增序列(1…n)的表——Temp,并将它与目标字符串所在的表Src进行笛卡尔运算.(Temp表的记录数要不小于遍历的目标字符串的长度) 2.过滤掉序列值大于串长的行. ...
- Apache:如何利用.htaccess文件对PHP网站或文件进行伪静态处理
来源:http://www.ido321.com/1123.html 今天get了一招:利用.htaccess文件对PHP网站或文件进行伪静态处理. 一.检查服务器是否支持伪静态处理: 必 须要空间支 ...
- php环境配置中各个模块在网站建设中的功能
上一篇配置环境的时候,我们注意到,有四个模块需要配置,那么,这四个模块分别有哪些功能呢? 一.php php是我们的用来创建动态网页的强有力的脚本语言,安装过程中我们直接解压到某一个路径就好了,比 ...