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. 接收串口数据0x00 strlen函数会截断

    写个串口接收程序接收到之后,用了一个上strlen,结果数据不全了,百度了下 strlen所作的仅仅是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域) ...

  2. Nginx阅读笔记(三)之proxy_pass用法

    在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走,如果没有/,则会把匹配的路径部分也给代理走. 假设访问 ...

  3. 多少遍ner让他加56看6

    http://www.huihui.cn/share/8112372 http://www.huihui.cn/share/8112363 http://www.huihui.cn/share/811 ...

  4. HDFS写入和读取流程

    HDFS写入和读取流程 一.HDFS HDFS全称是Hadoop Distributed System.HDFS是为以流的方式存取大文件而设计的.适用于几百MB,GB以及TB,并写一次读多次的场合.而 ...

  5. Js中的多条件排序,多列排序

    參见github: https://github.com/Teun/thenBy.js

  6. Android GPS应用:临近警告

    前面介绍过LocationManager有一个addProximityAlert(double latitude,double longitude,float radius,long expirati ...

  7. 错误处理try catch

    <?phpfunction inverse($x) { if (!$x) { throw new Exception('被除数不能为0'); } if ($x>31) { throw ne ...

  8. bresenham算法的FPGA的实现2

    在上一篇里http://www.cnblogs.com/sepeng/p/4045593.html <bresenham算法的FPGA的实现1>已经做了一个整体框架的布局,但是那个程序只是 ...

  9. Flask web开发 请求拦截和预处理

    我们在开发WEB应用时,往往会需要对所有的url请求进行拦截,做些预处理,比如权限处理.日志等统一处理. 本文介绍一下Flask中的处理机制.我们通过一个简单的例子来说明. 1.编写一个简单应用 ru ...

  10. linux下java窗口,正确显示中文

    Tip1 1.在 JAVA_HOME/jre/lib/fonts/ 下建立个目录 fallback 2.在 fallback 里弄个中文字体最简单ln一下就好了 比如: ln -s /usr/shar ...