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 ...
随机推荐
- 新买一款打印机hp5525N
11900 RMB 彩色.激光.彩打. 让法国的工艺工程师给改成法语的了.
- VS2013配置opencv3.0.0 (win8.1)
今天下载了最新版本的opencv3.0.0,之前一直是opencv2.4.8 点击.exe文件,我将解压后的文件夹放在D:\盘,取名opencv30,D:\opencv30 添加环境变量:D:\ope ...
- [转]Centos6.5使用yum安装mysql—配置MySQL允许远程登录
一.mysql安装 第1步.yum安装mysql[root@stonex ~]# yum -y install mysql-server安装结果:Installed: mysql-server ...
- 【转】如何在CentOS/RHEL中安装基于Web的监控系统 linux-das
Linux-dash是一款为Linux设计的基于Web的轻量级监控面板.这个程序会实时显示各种不同的系统属性,比如CPU负载.RAM使用率.磁盘使用率.网速.网络连接.RX/TX带宽.登录用户.运行的 ...
- 三、nginx301跳转302跳转
301跳转设置: server { listen 80; server_name downcc.com; rewrite ^/(.*) http://www.downcc.com/$1 permane ...
- Jquery moblie中的分栏布局
大家好,很高兴又与大家见面了,今天我要给大家展示的是自己对jquery moblie中网格布局的理解.可能不是尽善尽美,希望大家多多体谅! 在jquery moblie中有两种布局,一种是表格布局( ...
- [JBoss] JNDI与JBossNS
JNDI的作用 JNDI是 Java 命名与目录接口(Java Naming and Directory Interface). 随着分布式应用的发展,远程访问对象访问成为常用的方法.虽然说通过Soc ...
- openssl生成pem,密钥证书的创建
使用OpenSSL生成证书 首先得安装OpenSSL软件包openssl,安装了这个软件包之后,我们可以做这些事情: o Creation of RSA, DH and DSA Key Paramet ...
- Java中的字符串驻留
转自:http://www.cdtarena.com/javapx/201307/9088.html 最近在工作的时候,一句再正常不过的代码String a = “hello” + “world”;被 ...
- 前端面试题整理(js)
1.HTTP协议的状态消息都有哪些? HTTP状态码是什么: Web服务器用来告诉客户端,发生了什么事. 状态码分类: 1**:信息提示.请求收到,继续处理2**:成功.操作成功收到,分析.接受3** ...