POJ 1422 Air Raid
题目链接:
http://poj.org/problem?id=1422
Description
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
题意描述:
输入村庄的个数以及哪两个村庄有道路,有向图,无回路,问每条路只能被走一次,最少需要几个伞兵。
解题思路:
问题是求每条路只能走一次,问最少需要几个伞兵能将这几个村庄全部走完,那么求的是最小路径覆盖数,为什么不是最小顶点覆盖呢,因为求顶点只会到达点,而此题求到达点都还能沿着路访问其他顶点,故求的是最小路径覆盖。
AC代码:
#include<stdio.h>
#include<string.h>
int maxmatch();
int path(int u);
int n,m,e[][],match[],book[];
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(e,,sizeof(e));
while(m--)
{
scanf("%d%d",&i,&j);
e[i][j]=;
}
printf("%d\n",n-maxmatch());
}
return ;
}
int maxmatch()
{
int i,res=;
memset(match,,sizeof(match));
for(i=;i<=n;i++)
{
memset(book,,sizeof(book));
res += path(i);
}
return res;
}
int path(int u)
{
int i;
for(i=;i<=n;i++)
{
if(e[u][i] && !book[i])
{
book[i]=;
if(!match[i] || path(match[i]))
{
match[i]=u;
return ;
}
}
}
return ;
}
POJ 1422 Air Raid的更多相关文章
- POJ 1422 Air Raid(二分图匹配最小路径覆盖)
POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
- poj 1422 Air Raid (二分匹配)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6520 Accepted: 3877 Descript ...
- poj——1422 Air Raid
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8577 Accepted: 5127 Descript ...
- poj 1422 Air Raid 最少路径覆盖
题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...
- POJ 1422 Air Raid (最小路径覆盖)
题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...
- POJ - 1422 Air Raid 二分图最大匹配
题目大意:有n个点,m条单向线段.如今问要从几个点出发才干遍历到全部的点 解题思路:二分图最大匹配,仅仅要一条匹配,就表示两个点联通,两个点联通仅仅须要选取当中一个点就可以,所以有多少条匹配.就能够减 ...
- POJ - 1422 Air Raid(DAG的最小路径覆盖数)
1.一个有向无环图(DAG),M个点,K条有向边,求DAG的最小路径覆盖数 2.DAG的最小路径覆盖数=DAG图中的节点数-相应二分图中的最大匹配数 3. /* 顶点编号从0开始的 邻接矩阵(匈牙利算 ...
- POJ——T 1422 Air Raid
http://poj.org/problem?id=1422 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8579 A ...
- POJ 1442 Air Raid(DAG图的最小路径覆盖)
题意: 有一个城镇,它的所有街道都是单行(即有向)的,并且每条街道都是和两个路口相连.同时已知街道不会形成回路. 可以在任意一个路口放置一个伞兵,这个伞兵会顺着街道走,依次经过若干个路口. 问最少需要 ...
随机推荐
- node学习心得
此次学习主要使用的是基于nodejs平台的web应用开发框架. 一.express的工程结构 1.bin/www:express的执行入口,存放可执行文件: 2.node_modules:存放pack ...
- springCloud系列教程01:Eureka 注册中心集群搭建
springCloud系列教程包含如下内容: springCloud系列教程01:Eureka 注册中心集群搭建 springCloud系列教程02:ConfigServer 配置中心server搭建 ...
- K:线性表的实现—链表
单链表的概念: 采用链式存储方式存储的线性表称之为链表,链表中每个节点包含存放数据元素的值的数据域和存放指向逻辑上相邻节点的指针域.若一个节点中只包含一个指针域,则称此链表为单链表. 单链表的特点: ...
- Ajax 原生和jQuery的ajax用法
https://www.cnblogs.com/jach/p/5709175.html form数据的序列化: $('#submit').click(function(){ $('#form').se ...
- S2 深入.NET和C#编程 一: 深入C#.NET框架
深入C#.NET框架 1..NET框架 之一 推荐一个代码管理平台,博客发布平台 git 之前的复习: 学习的网站: git github.com 2.类和对象的关系 Dept de ...
- thinkphp5使用PHPExcel导入Excel数据
安装PHPExcel扩展类 地址:https://github.com/PHPOffice/PHPExcel ①通过composer安装 ②手动下载, 放在项目的extend目录下 代码中引入 由于P ...
- 《UNP》学习之TCP状态转换
CLOSED:TCP起始状态 LISTEN:绑定端口后进入listen状态,一般是服务端 SYN_SENT:发送SYN连接请求,主动打开连接的一方进入SYN_SENT SYN_RCVD:接收到SYN连 ...
- Android -- NestedScrolling滑动机制
1,如今NestedScrolling运用到很多地方了,要想好看一点的滑动变换,基本上就是使用这个来完成的,让我们来简单的了解一下. 2,NestedScrolling机制能够让父View和子View ...
- [js高手之路]寄生组合式继承的优势
在之前javascript面向对象系列的文章里面,我们已经探讨了组合继承和寄生继承,回顾下组合继承: function Person( uName ){ this.skills = [ 'php', ...
- MicroPython+北斗+GPS+GPRS:TPYBoardv702短信功能使用说明
转载请以链接形式注明文章来源(MicroPythonQQ技术交流群:157816561,公众号:MicroPython玩家汇) TPYBoardv702是目前市面上唯一支持通信定位功能的MicroPy ...