HDU-1151
Air Raid
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3661    Accepted Submission(s): 2408
a town where all the streets are one-way and each street leads from one
intersection to another. It is also known that starting from an
intersection and walking through town's streets you can never reach the
same intersection i.e. the town's streets 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.
program should read sets of data. The first line of the input file
contains the number of the data sets. Each data set specifies the
structure of a town and has the format:
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.
result of the program is on standard output. For each input data set
the program prints on a single line, starting from the beginning of the
line, one integer: the minimum number of paratroopers required to visit
all the intersections in the town.
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
/**
题意:有向无环图的最小路径覆盖
做法:二分图最大匹配 有向无环图的最小路径覆盖 = 该图的顶点数-该图的最大匹配。
**/
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#define maxn 220
using namespace std;
int g[maxn][maxn];
int linker[maxn];
int used[maxn];
int n,m;
int dfs(int u)
{
for(int v = ; v<n; v++)
{
if(g[u][v] && used[v] == )
{
used[v] = ;
if(linker[v] || dfs(linker[v]))
{
linker[v] = u;
return ;
}
}
}
return ;
}
int hungary()
{
int res = ;
memset(linker,-,sizeof(linker));
for(int i=; i<n; i++)
{
memset(used,,sizeof(used));
res += dfs(i);
}
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&n,&m);
int u,v;
memset(g,,sizeof(g));
for(int i=; i<m; i++)
{
scanf("%d %d",&u,&v);
u--;
v--;
g[u][v] = ;
}
int res = hungary();
printf("%d\n",n - res);
}
return ;
}
HDU-1151的更多相关文章
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
		
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
 - hdu 1151 Air Raid(二分图最小路径覆盖)
		
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
 - 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 ...
 - (匹配  最小路径覆盖)Air Raid --hdu --1151
		
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...
 - 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条道路,城市的道路是单向. 现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...
 - J - Air Raid - hdu 1151(最小边覆盖)
		
题意:给一个有向无环图,求出来最少需要几个士兵可以遍历所有的边. 分析:有向无环图的最小边覆盖 = 点数 - 最大匹配数 为什么是这样的公式??可以思考一下,如果这N个点之间没有边,是不是应该有N个士 ...
 - HDU 1151 - Air Raid
		
很明显求最小路径覆盖 就是求最大匹配 #include <iostream> #include <cstdio> #include <cstring> #inclu ...
 
随机推荐
- BZOJ1861:[ZJOI2006]书架——题解
			
http://www.lydsy.com/JudgeOnline/problem.php?id=1861 (题面复制于洛谷) 题目描述 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上 ...
 - NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第二轮Day2题解
			
肝了两题... T1一眼题,分解质因数,找出2的个数和5的个数取min输出 #include<iostream> #include<cstring> #include<c ...
 - NOIP2015Day2T3运输计划(二分+树上差分)
			
做了这么多NOIPTG的题,这是唯一 一道一眼秒的T3(有时候T2还不会做QAQ)... 题目大意就不说了QWQ 思路大概是:啊最大值最小化,来个二分.检验mid的话,显然就是用最长路径减去所有边权& ...
 - (ex)BSGS题表
			
学了一下BSGS大概知道他是什么了,但是并没有做什么难题,所以也就会个板子.普通的BSGS,我还是比较理解的,然而exBSGS我却只理解个大概,也许还会个板子......(这个东西好像都会有一群恶心的 ...
 - 【枚举】 最大子矩阵(I)
			
题注:最大子矩形问题的解决办法最初由中国国家集训队王知昆前辈整理并发表为论文,在此说明并感谢. Definition 给你一个大矩形,里面有一些障碍点,求一个面积最大的矩形,满足该矩形在大矩形内部且该 ...
 - JavaScript时间戳与其格式化
			
在 PHP + MySQL (日期类型为datetime) + ajax 应用中,有时候需要用 JavaScript 将时间戳类型格式化为一般的时间类型格式.下面提供一些转换的方法,比较常见的一些总结 ...
 - 实体框架(Entity Framework)快速入门--实例篇
			
在上一篇 <实体框架(Entity Framework)快速入门> 中我们简单了解的EF的定义和大体的情况,我们通过一步一步的做一个简单的实际例子来让大家对EF使用有个简单印象,看操作步骤 ...
 - 第一篇 关于Android Studio的快捷键
			
公司最近要培训Android的课程,但是发现现在官方网站上已经不提供了Eclipse ADT的下载了,都变成了Android Studio,可能是悲催了! 对于很多Eclipse转过来的同学,不适应的 ...
 - MSSQL Procudure Sample
			
代码: USE [Internal_Timesheet] GO /****** Object: StoredProcedure [dbo].[ManageTSReminder] Script Date ...
 - PowerDesigner16 用例图
			
用例图主要用来描述角色以及角色与用例之间的连接关系.说明的是谁要使用系统,以及他们使用该系统可以做些什么.一个用例图包含了多个模型元素,如系统.参与者和用例,并且显示这些元素之间的各种关系,如泛化.关 ...