POJ2594 最小路径覆盖
题意:
题意就是给你个有向无环图,问你最少放多少个机器人能把图全部遍历,机器人不能走回头路线。
思路:
如果直接建图,跑一遍二分匹配输出n - 最大匹配数会跪,原因是这个题目和以往见到的题目不一样的,区别就在,之前很多题目给的都是全边,就是假如 a->b b->c ,那么他一定会给你一条 a->c,因为a->c也是有指向关系的,而这个题目就没有给a->c,这就需要我们自己去找到所有可达边,一遍Floyd或者深搜都行,深搜是O(n^2)的,会快一点。给你在网上找的例子。
#include<stdio.h>
#include<string.h>
#define N_node 510
#define N_edge 300000
#define INF 100000000
typedef struct
{
int to ,next;
}STAR;
STAR E[N_edge];
int list[N_node] ,tot;
int mk_dfs[N_node] ,mk_gx[N_node];
int map[510][510];
void add(int a ,int b)
{
E[++tot].to = b;
E[tot].next = list[a];
list[a] = tot;
}
int DFS_XYL(int x)
{
for(int k = list[x] ;k ;k = E[k].next)
{
int to = E[k].to;
if(mk_dfs[to]) continue;
mk_dfs[to] = 1;
if(mk_gx[to] == -1 || DFS_XYL(mk_gx[to]))
{
mk_gx[to] = x;
return 1;
}
}
return 0;
}
int minn(int x ,int y)
{
return x < y ? x : y;
}
void Floyd(int n)
{
for(int k = 1 ;k <= n ;k ++)
for(int i = 1 ;i <= n ;i ++)
for(int j = 1 ;j <= n ;j ++)
map[i][j] = minn(map[i][j] ,map[i][k] + map[k][j]);
}
int main ()
{
int n ,m ,i ,j;
int a ,b;
while(~scanf("%d %d" ,&n ,&m) && n + m)
{
for(i = 1 ;i <= n ;i ++)
for(j = 1 ;j <= n ;j ++)
if(i == j) map[i][j] = 0;
else map[i][j] = INF;
for(i = 1 ;i <= m ;i ++)
{
scanf("%d %d" ,&a ,&b);
map[a][b] = 1;
}
Floyd(n);
memset(list ,0 ,sizeof(list));
tot = 1;
for(i = 1 ;i <= n ;i ++)
for(j = 1 ;j <= n ;j ++)
{
if(i == j || map[i][j] == INF) continue;
add(i ,j);
}
int sum = 0;
memset(mk_gx ,255 ,sizeof(mk_gx));
for(i = 1 ;i <= n ;i ++)
{
memset(mk_dfs ,0 ,sizeof(mk_dfs));
sum += DFS_XYL(i);
}
printf("%d\n" ,n - sum);
}
return 0;
}
POJ2594 最小路径覆盖的更多相关文章
- poj2594——最小路径覆盖
Description Have you ever read any book about treasure exploration? Have you ever see any film about ...
- poj2594最小路径覆盖+floyd
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8909 Accepted: 3 ...
- POJ2594 Treasure Exploratio —— 最小路径覆盖 + 传递闭包
题目链接:https://vjudge.net/problem/POJ-2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 655 ...
- poj2594 (最小路径覆盖 + floyd)
题目链接 http://poj.org/problem?id=2594) 题目大意: 一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过. 最小路径覆盖问题. 分析 ...
- poj2594 机器人寻找宝藏(最小路径覆盖)
题目来源:http://poj.org/problem?id=2594 参考博客:http://www.cnblogs.com/ka200812/archive/2011/07/31/2122641. ...
- POJ2594 Treasure Exploration(最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8550 Accepted: 3 ...
- 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 ...
随机推荐
- nignx的location正则匹配
原文链接:http://nginx.org/en/docs/http/ngx_http_core_module.html Syntax: location [ = | ~ | ~* | ^~ ] ur ...
- Docker安装开发环境
目录 Docker Docker 安装 Mysql Docker 安装Redis Docker 安装Zookeeper Docker Docker 安装 Mysql Docker 查看可用Mysql镜 ...
- 使用zap接收gin框架默认的日志并配置日志归档
目录 使用zap接收gin框架默认的日志并配置日志归档 gin默认的中间件 基于zap的中间件 在gin项目中使用zap 使用zap接收gin框架默认的日志并配置日志归档 本文介绍了在基于gin框架开 ...
- golang 遍历树状结构
以遍历Block结构为例,Block结构如下: type Block struct { Inside bool Nest int Boundary bool Incise []*Block } 可以看 ...
- react第三方库
作者:慕课网链接:https://www.zhihu.com/question/59073695/answer/1071631250来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- Nuxt.js vue服务端渲染
一.为什么要用Nuxt.js 原因其实不用多说,就是利用Nuxt.js的服务端渲染能力来解决Vue项目的SEO问题. 二.Nuxt.js和纯Vue项目的简单对比 1. build后目标产物不同 vue ...
- Centos7 Firewall 使用笔记
在 Centos 7 中防火墙由 firewalld 来管理,而不是以前的 iptables. 记录一下常用操作备查 firewall-cmd 操作 firewall-cmd --state 查看防火 ...
- HarmonyOS三方件开发指南(14)-Glide组件功能介绍
<HarmonyOS三方件开发指南>系列文章合集 引言 在实际应用开发中,会用到大量图片处理,如:网络图片.本地图片.应用资源.二进制流.Uri对象等,虽然官方提供了PixelMap进行图 ...
- mysql数据库忘记密码时如何修改密码
方法/步骤 1.进入 mysql 的 bin 目录下,打开 cmd ,在此之前关闭mysql服务,并且结束mysqld.exe进程 ...
- C++ 虚函数的内部实现
C++ 虚函数的内部实现 虚函数看起来是个玄之又玄的东西,但其实特别简单!了解了虚函数的内部实现,关于虚函数的各种问题都不在话下啦! 1. 知识储备 阅读这篇文章,你需要事先了解以下几个概念: 什么是 ...