题目链接:http://poj.org/problem?id=1422

Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you can never reach the same intersection 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.

题目描述:城镇里的街道从一个交叉口连接到另一个交叉口,街道都是单向的,并且从一个交叉口沿着街道出发不会回到相同的交叉口。伞兵降临在城镇的一个交叉口并可以沿着街道走向另一个没有被其他伞兵走过的交叉口,问城镇中的所有交叉口都被伞兵走过的情况下至少需要多少名伞兵。

算法分析:从题目中介绍城镇和街道的信息中可以知道是一个有向无环图,最少伞兵数量=DAG的最少路径覆盖(关于最少路径覆盖

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int n,m;
int g[maxn][maxn],linker[maxn],vis[maxn]; int dfs(int u)
{
for (int v= ;v<=n ;v++) if (g[u][v])
{
if (!vis[v])
{
vis[v]=;
if (linker[v]==- || dfs(linker[v]))
{
linker[v]=u;
return ;
}
}
}
return ;
} int hungary()
{
int ans=;
for (int i=n+ ;i<=*n ;i++)
{
memset(vis,,sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
} int main()
{
int t;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
memset(g,,sizeof(g));
memset(linker,-,sizeof(linker));
int x,y;
for (int i= ;i<m ;i++)
{
scanf("%d%d",&x,&y);
x += n;
g[x][y]=;
}
printf("%d\n",n-hungary());
}
return ;
}

poj 1422 Air Raid 最少路径覆盖的更多相关文章

  1. POJ 1422 Air Raid (最小路径覆盖)

    题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...

  2. POJ 1422 Air Raid(二分图匹配最小路径覆盖)

    POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...

  3. (hdu step 6.3.3)Air Raid(最小路径覆盖:求用最少边把全部的顶点都覆盖)

    题目: Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  4. 【网络流24题----03】Air Raid最小路径覆盖

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. POJ 1422 二分图(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7278   Accepted: 4318 Descript ...

  6. POJ 1422 Air Raid

    题目链接: http://poj.org/problem?id=1422 Description Consider a town where all the streets are one-way a ...

  7. poj——1422 Air Raid

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8577   Accepted: 5127 Descript ...

  8. HDU1151 Air Raid —— 最小路径覆盖

    题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  9. (step6.3.4)hdu 1151(Air Raid——最小路径覆盖)

    题意:     一个镇里所有的路都是单向路且不会组成回路. 派一些伞兵去那个镇里,要到达所有的路口,有一些或者没有伞兵可以不去那些路口,只要其他人能完成这个任务.每个在一个路口着陆了的伞兵可以沿着街去 ...

随机推荐

  1. 用户 'sa' 登录失败。 (Microsoft SQL Server,错误: 18456)

    今天登陆数据库的时候,却忽然登陆了不了,并且提示了这样的错: 解决方法: 1.用Windows身份登录数据库 2.安全性==>登录名==>双击sa 3.重设密码 4.状态==>登录: ...

  2. Silverlight IIs发布问题

    1.在IIS上部署系统没有问题,在vs中链接oracle中出错(数据连接不成功,请检查该数据库是否已启动尝试加载oracle客户端时引发BadImageFormatException.如果在安装32位 ...

  3. android sdk国内目录http://mirrors.neusoft.edu.cn/android/repository/

    http://mirrors.neusoft.edu.cn/android/repository/

  4. android ping网络是否成功

    public static boolean pingHost(String str) { //str 为要ping的IP地址 boolean result = false; try { Process ...

  5. 重定向语句Response.Redirect()方法与Response.RedirectPermanent()对搜索引擎页面排名的影响

    在ASP.NET中,开发人员经常使用Response.Redirect()方法,用编程的手法,将对老的URL的请求转到新的URL上.但许多开发人员没有意识到的是,Response.Redirect() ...

  6. 在Unity项目中使用Git

    (搬运自我在SegmentFault的博客) 本文参考了Unity官网的Mastering Unity Project Folder Structure - Version Control Syste ...

  7. 【WPF学习日记】——Window的DataContext绑定ViewModel

    1.全局的ViewModel绑定: a)设定全局的ViewModel(App.xaml中): 1 <Application x:Class="MyTest.App" 2 xm ...

  8. 【转】VNC配置

    配置VNC服务参数文件 编辑vncservers文件追加如下 #vi /etc/sysconfig/vncsevers VNCSERVERS="1:root" VNCSERVERA ...

  9. Django+Nginx+MongoDB+Mysql+uWsgi的搭建

    搭建目标如下: 图:系统架构图 这个系统可以提供web服务及其它查询应用服务,我用其做一个二手房信息搜集.处理及分发的系统,可以通过浏览器访问,也可以通过定制的客户端进行访问. 一.安装篇 1.下载安 ...

  10. Data Developer Center > Learn > Entity Framework > Get Started > Loading Related Entities

    Data Developer Center > Learn > Entity Framework > Get Started > Loading Related Entitie ...