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. win7 VMware Workstation Centos6.5虚机桥接上网设置 详解(靠谱)

    1.VMware Workstation 设置 2. vim /etc/sysconfig/network-scripts/ifcfg-eth0 NAME="System eth0" ...

  2. Linux下Tomcat catalina.out自动归档,以及logrotate 配置详解

    Linux下Tomcat catalina.out自动归档 如果 catalina.out 日志达到 2GB 大小的时候,Tomcat 因为缓存问题,便没有办法继续输出日志了.  为了避免这种情况,你 ...

  3. Recursive Depth first search graph(adj matrix)

    1 深度优先遍历邻接矩阵 1 邻接矩阵初始化 2 访问数组初始化 3 深度优先遍历邻接矩阵图 算法如下: bool MGraph[128][128]; bool visit[128]; int vex ...

  4. 下载的firebug-lite压缩包的调用方法

    把以下代码copy到地址栏按回车,等加载完毕之后(受网速限制,有时候等待会久一点,如果很久都无法加载,重试几次就ok了),就会显示firebug lite的窗口,这样不用更改页面任何东西,任何地方轻松 ...

  5. 第四节 二维条码与磁卡、IC卡、光卡之比较

    二维条码同其他几种自动识别技术的比较可见下表: 比较点 二维条形码 磁卡 IC卡 光卡 抗磁力 强 弱 中等 强 抗静电 强 中等 中等 强 抗损性 强可折叠可局部穿孔可局部切割 弱不可折叠不可穿孔不 ...

  6. poj 3691

    ac自动机+dp 自动机上的节点来作为状态 dp[i][j]表示长度为i状态为j至少需要转换多少个字符 #include <iostream> #include <cstdio> ...

  7. Android经常使用UI组件 - TextView

    TextView是Android里面用的最多的UI组件,一般使用在须要显示一些信息的时候,其不能输入,仅仅能初始设定或者在程序中改动. 实例:TextViewDemo 执行效果: 代码清单: 布局文件 ...

  8. OpenStack里对VPN的支持

    今天翻自己的笔记找到了点去年研究Cloudpipe的东西: 对于用VLAN隔开的项目内主机的访问,可以使用CloudPipe来进行VPN访问 其实就是把OpenStack和OpenVPN集成了一下,给 ...

  9. SparkContext主构造函数代码提取

    这是阅读sparkContext类的代码做的一个笔记.阅读这个类的时候,主要的任务就是搞清楚sparkContext是怎么构造的,java.C#的class的初始化都是放在一个方法中的,而scala的 ...

  10. 由zImage生成uImage

    一.手动使用mkimage命令 mkimage -A arm -O linux -T kernel -C none -a 30007fc0 -e 30007fc0 -n uImage   -d /wo ...