题意:

      题意就是给你个有向无环图,问你最少放多少个机器人能把图全部遍历,机器人不能走回头路线。

思路:

     如果直接建图,跑一遍二分匹配输出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 最小路径覆盖的更多相关文章

  1. poj2594——最小路径覆盖

    Description Have you ever read any book about treasure exploration? Have you ever see any film about ...

  2. poj2594最小路径覆盖+floyd

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8909   Accepted: 3 ...

  3. POJ2594 Treasure Exploratio —— 最小路径覆盖 + 传递闭包

    题目链接:https://vjudge.net/problem/POJ-2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 655 ...

  4. poj2594 (最小路径覆盖 + floyd)

    题目链接  http://poj.org/problem?id=2594) 题目大意: 一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过. 最小路径覆盖问题. 分析 ...

  5. poj2594 机器人寻找宝藏(最小路径覆盖)

    题目来源:http://poj.org/problem?id=2594 参考博客:http://www.cnblogs.com/ka200812/archive/2011/07/31/2122641. ...

  6. POJ2594 Treasure Exploration(最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8550   Accepted: 3 ...

  7. POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 9794   Accepted: 3 ...

  8. POJ-2594 Treasure Exploration,floyd+最小路径覆盖!

                                                 Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...

  9. POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8130   Accepted: 3 ...

随机推荐

  1. MySQL之九---分布式架构(Mycat/DBLE)

    MyCAT基础架构图 双主双从结构 MyCAT基础架构准备 准备环境  环境准备: 两台虚拟机 db01 db02 每台创建四个mysql实例:3307 3308 3309 3310 删除历史环境 p ...

  2. Codeforces 598D (ccpc-wannafly camp day1) Igor In the Museum

    http://codeforces.com/problemset/problem/598/D 分析:BFS,同一连通区域的周长一样,但查询过多会导致TLE,所以要将连通区域的答案储存,下次查询到该连通 ...

  3. Flink的日志配置

    ------------恢复内容开始------------ 介绍flink在本地运行和on yarn运行时的日志配置. 很多现代框架都是用门面模式进行日志输出,例如使用Slf4j中的接口输出日志,具 ...

  4. [THUPC2019] 找树

    一.题目 点此看题 二.解法 这道题很离谱啊,看上去是求一个最大值,其实是把生成树权值为 \(i\) 的个数都给算出来,因为权值很小. 既然是生成树可以考虑矩阵树定理,我们考虑他是求这样一个式子: \ ...

  5. unittest系列(一)unittest简介和示例

    unittest - 单元测试框架 单元测试框架是受到 JUnit 的启发,与其他语言中的主流单元测试框架有着相似的风格.其支持测试自动化,配置共享和关机代码测试.支持将测试样例聚合到测试集中,并将测 ...

  6. C# 通过ServiceStack 操作Redis——Set类型的使用及示例

    ServiceStack 程序集里面没有方法注解,我在这里将注解添加上去,有不当之处,欢迎指正 Console.WriteLine("---Set类型---"); //添加 set ...

  7. od快捷键

    视图.查看相关: Alt+l  记录 Alt+e 可执行模块 Alt+m 内存 Alt+c cpu(反汇编视图) Ctrl+p 补丁 Alt+k 调用堆栈 Alt+b 断点 Alt+f5 设置窗口总在 ...

  8. IdentityServer4是什么

    1 什么是IdentityServer4? IdentityServer4是用于ASP.NET Core的OpenID Connect和OAuth 2.0框架. 2 什么是OAuth 2.0? OAu ...

  9. 阳明-K8S训练营全部文档-2020年08月11日14:59:02更新

    阳明-K8S训练营全部文档 Docker 基础 简介 安装 基本操作 Dockerfile Dockerfile最佳实践 Kubernetes 基础 简介 安装 资源清单 Pod 原理 Pod 生命周 ...

  10. Redis系列-存储篇string主要操作命令

    Redis系列-存储篇string主要操作命令 通过上两篇的介绍,我们的redis服务器基本跑起来.db都具有最基本的CRUD功能,我们沿着这个脉络,开始学习redis丰富的数据结构之旅,当然先从最简 ...