POJ1422 Air Raid 【DAG最小路径覆盖】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6763 | Accepted: 4034 |
Description
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
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
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
Sample Output
2
1
Source
对于DAG,求最小路径覆盖有例如以下公式:最小路径覆盖数 = 节点数 - 相应的二分图最大匹配数。
用电脑自带的绘图画了张草图,挫爆了 -_-!
题意:输入数据具体解释,t组数据。n个节点(从1開始)。m条有向边。u到v。
题解:套公式。
#include <stdio.h>
#include <string.h> const int maxn = 125;
int n, m;
int cx[maxn], cy[maxn];
bool visy[maxn], G[maxn][maxn]; void getMap() {
memset(G, 0, sizeof(G));
int u, v;
scanf("%d%d", &n, &m);
while(m--) {
scanf("%d%d", &u, &v);
G[u][v] = true;
}
} int findPath(int x) {
int i;
for(i = 1; i <= n; ++i) {
if(G[x][i] && !visy[i]) {
visy[i] = 1;
if(cy[i] == -1 || findPath(cy[i])) {
cy[i] = x; return 1;
}
}
}
return 0;
} int MaxMatch() {
int ans = 0, i;
memset(cx, -1, sizeof(cx));
memset(cy, -1, sizeof(cy));
for(i = 1; i <= n; ++i) {
memset(visy, 0, sizeof(visy));
if(cx[i] == -1) ans += findPath(i);
}
return ans;
} void solve() {
printf("%d\n", n - MaxMatch());
} int main() {
// freopen("stdin.txt", "r", stdin);
int t;
scanf("%d", &t);
while(t--) {
getMap();
solve();
}
return 0;
}
POJ1422 Air Raid 【DAG最小路径覆盖】的更多相关文章
- 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上的最小路径覆盖问题. 路径覆盖的定义:有向图中,路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且 ...
- HDU 1151 Air Raid(最小路径覆盖)
题目大意: 有n个城市,m条道路,城市的道路是单向. 现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...
- Air Raid(最小路径覆盖)
Description Consider a town where all the streets are one-way and each street leads from one interse ...
- uva1201 DAG 最小路径覆盖,转化为 二分图
大白例题P356 你在一座城市里负责一个大型活动的接待工作.你需要去送m个人从出发地到目的地,已知每个人的出发时间出发地点,和目的地点,你的任务是用尽量少的出租车送他们,使得每次出租车接客人,至少能提 ...
- 【LA3126 训练指南】出租车 【DAG最小路径覆盖】
题意 你在一座城市里负责一个大型活动的接待工作.明天将有m位客人从城市的不同的位置出发,到达他们各自的目的地.已知每个人的出发时间,出发地点和目的地.你的任务是用尽量少的出租车送他们,使得每次出租车接 ...
- 训练指南 UVALive - 3126(DAG最小路径覆盖)
layout: post title: 训练指南 UVALive - 3126(DAG最小路径覆盖) author: "luowentaoaa" catalog: true mat ...
- 1350 Taxi Cab Scheme DAG最小路径覆盖
对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...
- hdu3861 The King’s Problem 强连通缩点+DAG最小路径覆盖
对多校赛的题目,我深感无力.题目看不懂,英语是能懂的,题目具体的要求以及需要怎么做没有头绪.样例怎么来的都不明白.好吧,看题解吧. http://www.cnblogs.com/kane0526/ar ...
随机推荐
- javascript获取页面各种高度
网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWi ...
- Eclipse 和 MyEclipse控制台console不停的自动跳动,跳出来解决方案
有时候Eclipse启动,控制台console不会自动跳出来,需要手工点击该选项卡才行,按下面的设置,可以让它自动跳出来(或不跳出来):由二种方法: 一.windows -> prefer ...
- java Native 方法
一. 什么是Native Method 简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由非j ...
- iOS开发之XMPP即时通讯简单实现
首先搭载服务器和数据库 搭载服务器我用的是openfire,数据库用的是mysql 这里推荐两个链接 配置mysql,用的是mysql workbench http://justsee.iteye.c ...
- Android开发--CardView使用
Android5.0中向我们介绍了一个全新的控件–CardView,从本质上看,可以将CardView看做是FrameLayout在自身之上添加了圆角和阴影效果.请注意:CardView被包装为一种布 ...
- Testin_百度百科
Testin_百度百科 Testin 编辑 目录 1测试平台 2三大特性 #1 真机终端云,节省测试设备购买租赁成本#2 自动化测试,节省测试人员成本及时间# ...
- 基于二叉树和数组实现限制长度的最优Huffman编码
具体介绍详见上篇博客:基于二叉树和双向链表实现限制长度的最优Huffman编码 基于数组和基于链表的实现方式在效率上有明显区别: 编码256个符号,符号权重为1...256,限制长度为16,循环编码1 ...
- hdu 4861 Couple doubi(数论)
题目链接:hdu 4861 Couple doubi 题目大意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+⋯+(p−1)i%p,两个人轮流取,假设DouBiNan的值大的话就输出YES, ...
- C语言指针和数组知识总结(下)
一.数组指针: 数组指针就是一个指针,只不过它指向的是一个数组.可以通过如下方式来定义 typedef int Array[5]; //数组类型 Array* m; //数组定义 还有一种更 ...
- cocos2d-x 制作资源下载页面
开发游戏中用到从http 服务器下载文件的操作,所以要有个界面显示下载进度,同时联网采用curl库,因为下载是同步的操作,所以用了多线程 啥也不说,直接贴代码.我是采用ccbi做的页面,你也可以做一个 ...