hdu1151Air Raid

原创 2013年12月02日 23:35:25

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(最小路径)

二分匹配
  • qq_30727593
  • qq_30727593
  • 2016年05月24日 13:19
  • 51

hdu1151Air Raid——最小路径覆盖

hdu1151Air Raid:http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 2000/1000 ...
  • hahaAll
  • hahaAll
  • 2015年12月23日 16:17
  • 173

hdu1151Air Raid【最小路径覆盖】

Description Consider a town where all the streets are one-way and each street leads from one inte...
  • zhou_yujia
  • zhou_yujia
  • 2016年10月08日 15:21
  • 151

hdu1151Air Raid (二分匹配,最小路径覆盖)

Problem Description Consider a town where all the streets are one-way and each street leads from on...
  • u010372095
  • u010372095
  • 2014年07月28日 15:54
  • 702

服务器RAID配置详解

第一部分 如何配置阵列开机自检过程中有Ctrl+A提示:《阵列卡不同,按键组合也不同,也有Ctrl+H的,这个主要根据阵列卡来的,不过,系统启动的时候都有提示的,看屏幕就行了》   按下组合键...
  • loveyaqin1990
  • loveyaqin1990
  • 2014年09月10日 12:27
  • 1905

Python监控RAID健康状况

环境:Ubuntu 64 工具:MegaCli Python 2.7一、MegaCli在Ubuntu下的安装  可以在这里下载到你需要的MegaCli的zip包。   解压之后得到一个rpm的安...
  • ah_luozhi
  • ah_luozhi
  • 2017年03月10日 14:50
  • 476

RAID各级别、软RAID

0.目录目录 RAID 1 什么是RAID 2 使用场景 3 RAID如何提高磁盘耐用性和IO能力 4 RAID级别 RAID各级别组织方式 1 RAID-0 11 实现方式 12 指标及分析 2 R...
  • wangzhenyu177
  • wangzhenyu177
  • 2016年12月21日 22:02
  • 218

什么是RAID? 硬RAID 和软RAID的区别是什么?

近年来 NAS越加火爆,但是在使用 NAS时无法避免的一个东西就是 RAID,那么什么是 RAID 呢?又有那些坑呢? 什么是 RAIDRAID 是Redundant Array of Indepen...
  • csdn100861
  • csdn100861
  • 2016年05月17日 21:43
  • 7738

RAID 常见类型介绍

之前一直听说RAID,但从来没有真正去理解RAID是什么,今天突然想起来看看,就自己写下来帮助记忆和查看。 RAID(Redundent Array of Independent Disk),意思是...
  • Post_Yuan
  • Post_Yuan
  • 2016年12月08日 11:37
  • 1370

RAID中VD—虚拟驱动器的理解

百度知道上有一个关于RAID概念的提问,答案很清晰明了。问题是关于RAID中的虚拟驱动器的: raid 的 虚拟磁盘的 含义 为什么 做raid 要建立 raid 磁盘组 ? 在 r...
  • lyjshen
  • lyjshen
  • 2016年10月09日 17:21
  • 1794
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hdu1151Air Raid
举报原因:
原因补充:

(最多只允许输入30个字)