Air Raid(最小路径覆盖)
Description
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
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
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
关于最小覆盖:http://blog.csdn.net/u014665013/article/details/49870029
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
#define MAX 125
int n;
int map[MAX][MAX];
bool visited[MAX];
int match[MAX]; bool find(int i) ///查找当前的i是否可以匹配
{
int j;
for(j=1;j<=n;j++)
{
if(map[i][j]&&!visited[j])
{
visited[j]=1;
if(match[j]==-1||find(match[j]))
{
match[j]=i;
return 1;
}
}
}
return 0;
}
int main()
{
int k,x,y,ans;
int T;
scanf("%d",&T);
while(T--)
{
ans=0;
scanf("%d%d",&n,&k);
memset(map,0,sizeof(map));
memset(match,-1,sizeof(match)); for(int i=0;i<k;i++)//对有意思的进行初始化
{
scanf("%d%d",&x,&y);
map[x][y]=1;
}
for(int i=1;i<=n;i++)
{
memset(visited,0,sizeof(visited));//开始标记为全部没有访问
if(find(i))
ans++;
}
printf("%d\n",n-ans);
}
return 0;
}
Air Raid(最小路径覆盖)的更多相关文章
- 【网络流24题----03】Air Raid最小路径覆盖
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- (hdu step 6.3.3)Air Raid(最小路径覆盖:求用最少边把全部的顶点都覆盖)
题目: Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU1151 Air Raid —— 最小路径覆盖
题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- POJ 1422 Air Raid (最小路径覆盖)
题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...
- (step6.3.4)hdu 1151(Air Raid——最小路径覆盖)
题意: 一个镇里所有的路都是单向路且不会组成回路. 派一些伞兵去那个镇里,要到达所有的路口,有一些或者没有伞兵可以不去那些路口,只要其他人能完成这个任务.每个在一个路口着陆了的伞兵可以沿着街去 ...
- hdu 1151 Air Raid 最小路径覆盖
题意:一个城镇有n个路口,m条路.每条路单向,且路无环.现在派遣伞兵去巡逻所有路口,伞兵只能沿着路走,且每个伞兵经过的路口不重合.求最少派遣的伞兵数量. 建图之后的就转化成邮箱无环图的最小路径覆盖问题 ...
- Air Raid(最小路径覆盖)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7511 Accepted: 4471 Descript ...
- poj 1422 Air Raid 最少路径覆盖
题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- POJ1422 Air Raid 【DAG最小路径覆盖】
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6763 Accepted: 4034 Descript ...
随机推荐
- Dom选择器及操作文本内容
文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式.我们最为关心的是,DOM把 ...
- html之ul标签
html之无序列表,建议使用样式来定义列表的类型. 通常和li配对使用 可选属性: type:disc 圆点,circle圆圈,square方块 compact:显示效果比正常更小巧 <body ...
- Extjs4.2.1中的helloworld
ExtJS最新正式版4.2.1下载地址:http://pan.baidu.com/s/1qWNt2kk (开发api文档:https://github.com/extjs-doc-cn/ext4api ...
- Tortoisesvn单个文件夹checkout
- 09 Mysql数据库在Linux下的使用
1. 创建数据库 1.1 启动Mysql [root@localhost ~]# mysql -h127.0.0.1 -uroot -pmysql Warning: Using a password ...
- ARM与x86之3--蝶变ARM
http://blog.sina.com.cn/s/blog_6472c4cc0100lqr8.html 蝶变ARM 1929年开始的经济大萧条,改变了世界格局.前苏联的风景独好,使得相当多的人选择了 ...
- android如何播放资源文件夹raw中的视频
转自这里 videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/&qu ...
- 更改AD查询LDAP条目的1000限制
解除LDAP导入时的AD条目查询限制 解除LDAP导入或读取AD用户数限制问题 更改AD查询LDAP条目的1000限制 来源:http://www.jiancool.com/article/55373 ...
- c++中的peek函数
c++中 cin.peek()函数 其返回值是一个char型的字符,返回值是指针指向的当前字符, 但是只是观测,指针任停留在当前位置,并不后移.如果要访问的字符是文件结束符,则函数值是EOF(-1); ...
- Navicat 11使用技巧
入门 Navicat 是一个可多重连接的数据库管理工具,它可让你连接到 MySQL.Oracle.PostgreSQL.SQLite.SQL Server 和/或 MariaDB 数据库,让管理不同类 ...