poj2594 (最小路径覆盖 + floyd)
题目链接 http://poj.org/problem?id=2594)
题目大意:
一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过。 最小路径覆盖问题。
分析:
这时最小路径覆盖问题, 最小路径覆盖 = |V| - 最大匹配数。 (有关最小路径覆盖,最大匹配问题,相关概念不懂得 点这里) 当然做这道题还有一个坑!! 如果有向图的边有相交的情况,那么就不能简单的对原图求二分匹配了 详细讲解看这。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<cstring>
using namespace std; int n, m, sum, ans[], v[], map[][];
void floyd() // 求图的闭包
{
for(int k = ; k <= n; k++)
{
for(int i = ; i <= n; i++)
{
if(map[i][k] == )
{
for(int j = ; j <= n; j++)
{
if(map[k][j] == )
map[i][j] = ;
}
}
}
}
} int dfs(int x) // 找增广路径
{
for(int i = ; i <= n; i++)
{
if(map[x][i] == && v[i] == )
{
v[i] = ;
if(ans[i] == || (ans[i] != && dfs(ans[i]) == ))
{
ans[i] = x;
return ;
}
}
}
return ;
}
int main()
{
while(scanf("%d%d", &n, &m) != EOF && (n || m))
{
memset(ans, , sizeof(ans));
memset(map, , sizeof(map));
for(int i = ; i <= m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
map[x][y] = ;
} floyd(); sum = ;
for(int i = ; i <= n; i++) // 求最大匹配
{
memset(v, , sizeof(v));
int t = dfs(i);
if(t == )
sum++;
}
printf("%d\n", n - sum);
}
return ;
}
poj2594 (最小路径覆盖 + floyd)的更多相关文章
- poj2594最小路径覆盖+floyd
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8909 Accepted: 3 ...
- POJ 3216 最小路径覆盖+floyd
Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6646 Accepted: 178 ...
- poj2594——最小路径覆盖
Description Have you ever read any book about treasure exploration? Have you ever see any film about ...
- POJ2594 最小路径覆盖
题意: 题意就是给你个有向无环图,问你最少放多少个机器人能把图全部遍历,机器人不能走回头路线. 思路: 如果直接建图,跑一遍二分匹配输出n - 最大匹配数会跪,原因是这个题目和以 ...
- POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 9794 Accepted: 3 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8130 Accepted: 3 ...
- HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)
题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...
- hdu 4606 简单计算几何+floyd+最小路径覆盖
思路:将所有的直线的两个端点和城市混在一起,将能直接到达的两个点连线,求一次floyd最短路径.二分枚举bag容量,然后按给的要先后占领的城市由前向后,把能到一步到达的建一条边.然后求一次最小路径覆盖 ...
随机推荐
- css div 不能贴边
*{margin:0;padding:0} 在css 最前加上这句,取消所有内边距和外边距.
- iOS 详解NSXMLParser方法解析XML数据方法
前一篇文章已经介绍了如何通过URL从网络上获取xml数据.下面介绍如何将获取到的数据进行解析. 下面先看看xml的数据格式吧! <?xml version="1.0" enc ...
- Oracle- 备份单表结构和单表数据
在网上看到,有用,记录如下: 这是Oracle的备份表结构和数据,因为实际工作对表进行大规模的数据改动都要讲数据进行备份,否则丢了数据那是很头疼的事情. --创建一份表结构 create table ...
- HTML5----CSS显示半个字符
CSS显示半个字符的基本思路: 就是一个字写两遍,分别显示一半.这里就须要用到CSS伪元素:before和:after,记住这个"伪元素"的"伪"字,表明它本来 ...
- Microsoft.AspNet.FriendlyUrls发布到IIS后404报错的解决方案
我一个项目都基本上做完了,结果部署到我服务器的时候结果一直报404 找不到 一看global.asax有个路由注册的代码 public static void RegisterRoutes(Route ...
- nginx,FastCGI启动语句
/etc/init.d/nginx restart spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi
- OpenCV 读取.xml文件
OpenCV 只提供了读取和存储.xml和.yml 文件格式的函数. 读取.xml文件的C++例程如下: cv::FileStorage fs; //OpenCV 读XML文件流 cv::Mat De ...
- [React] Set up React apps with zero configuration
The React team has an official Command Line Interface (CLI) for building React projects called " ...
- [React Native] Reusable components with required propType
In this React Native lesson, we will be creating a reusable Badge component. The component will also ...
- IOS笔记 #pragma mark的用法
简单的来说就是为了方便查找和导航代码用的. 下面举例如何快速的定位到我已经标识过的代码. #pragma mark 播放节拍器 - (void) Run:(NSNumber *)tick { //.. ...