Air Raid

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2704    Accepted Submission(s): 1762

Problem Description
Consider 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.

 
Input
Your 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.

 
Output
The 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.

 
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
 
Sample Output
2
1
 
Source
 
思路:在做hdu3861(The King's Problem)的时候,题目大意看一遍又一遍也不明白测试用例。
And the king must insure that in each state we can ether go from u to v or go from v to u between every pair of cities (u, v) without passing any city which belongs to other state.然后在参考网上题目解释才突然明白缩点之后求DAG上最小路径覆盖的,因为之前没涉及到这个问题,所有读题目都成问题,
看来“同志仍需努力啊”,我的小伙伴们都踢球去了,我毅然决定呆在computer lab研究一下,最小路径覆盖和二分匹配的关系。
这到题目算是二分匹配的入门题目了,然后每次选择未被覆盖的点,去找增广路,用DFS实现匈牙利算法。
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 120+10;
vector<int> G[maxn];
int from[maxn], tot;
bool use[maxn];
int gn, gm;
//Accepted 1151 0MS 332K 1104 B G++ Achiberx
bool match(int x) {
for(int i = 0; i < (int)G[x].size(); i++) {
int v = G[x][i];
if(!use[v]) {
use[v] = true;
if(from[v] == -1 || match(from[v])) {
from[v] = x;
return true;
}
}
}
return false;
} int hungary() {
tot = 0;
memset(from, -1, sizeof(from));
for(int i = 1; i <= gn; i++) {
memset(use, false, sizeof(use));
if(match(i)) tot++;
}
return tot;
} int main()
{
int T, u, v;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &gn, &gm);
for(int i = 0; i < maxn; i++) G[i].clear();
for(int i = 1; i <= gm; i++) {
scanf("%d%d", &u, &v);
G[u].push_back(v);
}
int res = hungary();
printf("%d\n", gn-res);
} }

hdu1151Air Raid的更多相关文章

  1. HDU1151Air Raid(二分图的最大匹配)

    题目大意: 有一个城镇,它的所有街道都是单行的,并且每条街道都是和两个路口相连.同时已知街道不会形成回路. 你的任务是编写程序求最小数量的伞兵,这些伞兵可以访问(visit)所有的路口.

  2. 一张“神图”看懂单机/集群/热备/磁盘阵列(RAID)

    单机部署(stand-alone):只有一个饮水机提供服务,服务只部署一份 集群部署(cluster):有多个饮水机同时提供服务,服务冗余部署,每个冗余的服务都对外提供服务,一个服务挂掉时依然可用 热 ...

  3. 什么是RAID?RAID有什么用?RAID原理

    什么是RAID 硬盘是个很脆弱的东西,它经常会坏掉.所以,为了保证服务器可靠耐用,硬盘必须时时刻刻保持可用.所以有了RAID这个东西.它的目的是将好几个硬盘合并在一起,就算硬盘坏了一个,剩下还有好几个 ...

  4. 3.raid基础应用

    raid分为软备份和硬备份 软备份主要用来实验 应备份用于生产环境 raid0(带区卷)    具有很高的数据传输率,没有数据的冗余  1块磁盘 raid1(镜像卷)  提供数据冗余,利用率低  2块 ...

  5. linux基础-磁盘阵列(RAID)实例详解

    磁盘阵列(RAID)实例详解 raid技术分类 软raid技术 硬raid技术 Raid和lvm的区别 为什么选择用raid RAID详解 RAID-0 RAID-1 RAID-5 Raid-10 R ...

  6. Dell R730 配置完RAID后装系统找不到硬盘。

    1. 各硬盘只是灯都正常.硬件无故障. 2. 8个600G硬盘做的RAID0和RAID5后都在装系统选盘处找不到硬盘.(注意: 第一次做raid 时,没有进行初始化init.后补做也无效,一直复现这个 ...

  7. Linux学习之CentOS(二十八)--RAID原理基础及Linux下软件RAID配置

    一.RAID的原理基础 在 讲解RAID的原理基础之前,我们首先来了解一下传统磁盘的劣势.我们知道一台PC机种都会包含CPU.内存.主板.硬盘.网卡等硬件,影响计算机性能的 组建包括:CPU.主板总线 ...

  8. Raid 介绍以及软raid的实现

    RAID: old Redundant Arrays of Inexpensive Disks (廉价磁盘冗余阵列) new Redundant Arrays of Independent Disks ...

  9. Linux RAID卡优化

    200 ? "200px" : this.width)!important;} --> 介绍 我们的生产服务器经常会做raid存储,但是单单做了raid就能保证性能高效和数据 ...

随机推荐

  1. apache加载php模块失败

    LoadModule php5_module "G:/php54/php5apache2_2.dll" apache2 conf加入这个之后无法加载 解决办法 在这句之前加入PHP ...

  2. shell学习之常用命令总结

    1.find命令 主要用途:主要用来做文件查找. 使用方法:查找文件的方式可以基于:文件名,文件时间属性,文件的所有者和组,文件权限属性,文件类型属性,文件大小,另外可以指定 查找目录的深度,排除指定 ...

  3. sql server单表导入、导出

    sql server单表导入.导出(通过CSV文件) 导出:直接打开查询分析器查询要导出表的信息(select *  from 表),得到的结果全选,右键另存为 xxx.csv文件  (得到该表的所有 ...

  4. Linux网卡设置

    http://blog.chinaunix.net/uid-20149676-id-1733254.html

  5. mysql记录慢查询

    1,配置开启 Linux: 在mysql配置文件my.cnf中增加 log-slow-queries=/var/lib/mysql/slowquery.log (指定日志文件存放位置,可以为空,系统会 ...

  6. Flash中用AS3做的游戏,导出apk安装到手机上滤镜效果出不来为什么?

    主要原因是,导出apk文件时渲染模式设置成了GPU.改掉就行了.

  7. c++, 虚基派生 : 共同基类产生的二义性的解决办法

    虚基派生 //虚继承 #include <iostream> using namespace std; #include <string> //---------------- ...

  8. Spring MVC 3.x 版本使用 @ResponseBody 返回乱码

    由于万恶的Spring MVC 默认返回编码 是 ISO-8859-1, 使用如下配置, 可以将编码专为UTF-8, <bean class="org.springframework. ...

  9. MAC X OS 自定义分辨率

    1 vi /Library/Preferences/SystemConfiguration/com.apple.Boot.plist 2 3 将该文件修改成如下内容: 4 5 <key>G ...

  10. Android Matrix(坐标矩阵)

    Android Matrix 2016-02-26 14:38:10 介绍 中文名:坐标矩阵 高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 在Android里面,Matr ...