HDU1151 Air Raid —— 最小路径覆盖
题目链接:https://vjudge.net/problem/HDU-1151
Air Raid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5630 Accepted Submission(s): 3785
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.
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.
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
1
题解:
单纯的求最小路径覆盖。最小路径覆盖 = 结点数 - 最大匹配数。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9+;
const int MAXN = +; int n;
int M[MAXN][MAXN], link[MAXN];
bool vis[MAXN]; bool dfs(int u)
{
for(int i = ; i<=n; i++)
if(M[u][i] && !vis[i])
{
vis[i] = true;
if(link[i]==- || dfs(link[i]))
{
link[i] = u;
return true;
}
}
return false;
} int hungary()
{
int ret = ;
memset(link, -, sizeof(link));
for(int i = ; i<=n; i++)
{
memset(vis, , sizeof(vis));
if(dfs(i)) ret++;
}
return ret;
} int main()
{
int T, m;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
memset(M, false, sizeof(M));
for(int i = ; i<=m; i++)
{
int u, v;
scanf("%d%d", &u, &v);
M[u][v] = true;
} int cnt = hungary();
printf("%d\n", n-cnt);
}
}
HDU1151 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 ...
- 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 ...
- hdu1151+poj2594(最小路径覆盖)
传送门:hdu1151 Air Raid 题意:在一个城镇,有m个路口,和n条路,这些路都是单向的,而且路不会形成环,现在要弄一些伞兵去巡查这个城镇,伞兵只能沿着路的方向走,问最少需要多少伞兵才能把所 ...
- Hdu1151 Air Raid(最小覆盖路径)
Air Raid Problem Description Consider a town where all the streets are one-way and each street leads ...
- poj 1422 Air Raid 最少路径覆盖
题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...
随机推荐
- CentOS 7下安装Composer + Laravel
1.wget https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer chmod a+x /usr/local/bi ...
- 大数据学习——linux常用命令(四)
四 查到命令 1 查找可执行的命令所在的路径 which ls 查ls命令所在的路径 2 查找可执行的命令和帮助的位置 whereiis ls 3 从某个文件夹开始查找文件 find / -name ...
- Leetcode 235.二叉搜索树的公共祖先
二叉搜索树的公共祖先 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 ...
- 《Docker容器与容器云》读书笔记
云计算平台 云计算是一种资源的服务模式,该模式可以实现随时随地.便捷按需地从可配置计算资源共享池中获取所需资源(如网络.服务器.存储.应用及服务),资源能够快速供应并释放,大大减少了资源管理工作开销. ...
- oracle 9i/10g/11g(11.2.0.3)安装包和PATCH下载地址汇总
今天上PUB看见一位热心人汇总了这么个地址列表,转发来空间: 把下面的地址复制到讯雷里就可以下载. -------------------------------------------------- ...
- 在Ignite中使用线性回归算法
在本系列前面的文章中,简单介绍了一下Ignite的机器学习网格,下面会趁热打铁,结合一些示例,深入介绍Ignite支持的一些机器学习算法. 如果要找合适的数据集,会发现可用的有很多,但是对于线性回归来 ...
- 【区间筛】2017多校训练四 HDU6069 Counting Divisors
http://acm.hdu.edu.cn/showproblem.php?pid=6069 [题意] 给定l,r,k,求 d(n)是n的因子个数 [思路] [Accepted] #include&l ...
- SeLion数据驱动中遇到的问题,以及解决方案
问题描述: 使用selion框架数据驱动时,总是test ignored. 解决方案: 把这个dataprovider方法拿出来做单元测试.有详细报错. 问题1:使用wps保存,poi包只能解析xls ...
- react.js 给标识ref,获取内容
import React,{Component} from 'react' import ReactDOM from 'react-dom' class App extends Component{ ...
- 应对ADT(Eclipse)的No more handles解决办法
应对ADT(Eclipse)的No more handles解决方法 ADT(Eclipse)最近几天经常出现如下错误对话框:org.eclipse.swt.SWTError: No more han ...