题意:

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

思路:

     如果直接建图,跑一遍二分匹配输出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. 解决 DatePickerDialog 在 Android7.0 API24 上使用 AlertDialog.THEME_TRADITIONAL、AlertDialog.THEME_HOLO_DARK、AlertDialog.THEME_HOLO_LIGHT等样式时无法显示为 Spinner 样式的问题

    DatePickerDemoForAndroid24 解决 DatePickerDialog 在 Android7.0 API24 上使用AlertDialog.THEME_TRADITIONAL.A ...

  2. JVM 中的StringTable

    是什么 字符串常量池是 JVM 中的一个重要结构,用于存储JVM运行时产生的字符串.在JDK7之前在方法区中,存储的是字符串常量.而字符串常量池在 JDK7 开始移入堆中,随之而来的是除了存储字符串常 ...

  3. dom_bom学习

    1. bom是什么? browser object model(浏览器对象模型) 在浏览器中 window指的就是bom对象 //网页重定向 // window.location.href=" ...

  4. 关于PHP的__construct()函数

    1 <?php 2 header("Content-Type:text/html;charset=utf-8");//调整为utf-8编码格式 3 class car 4 { ...

  5. 为什么要从 Linux 迁移到 BSD2

    OpenZFS on Linux,是项目的 Linux 部分,目前有 345 个活跃的贡献者,有超过 5600 个提交,而且几乎每天都有提交!一些世界上最大的 CDN 和数据存储服务在 FreeBSD ...

  6. TensorFlow学习(2)

    TensorFlow学习(2) 一.jupyter notebook的安装和使用 1. 什么是jupyter notebook jupyter notebook(http://jupyter.org/ ...

  7. [WC2014]时空穿梭

    这才叫莫比乌斯反演题. 一.题目 点此看题 二.解法 也没有什么好的思路,我们不妨把暴力柿子写出来,我们想枚举直线,但是这道题不能枚举直线的斜率,所以就要用整数来表示直线,我们不妨枚举出发点和终止点的 ...

  8. golang 遍历树状结构

    以遍历Block结构为例,Block结构如下: type Block struct { Inside bool Nest int Boundary bool Incise []*Block } 可以看 ...

  9. linuxc语言图形化编程包含gtk/gtk.h编译总是报错找不到该文件的解决方法

    在编译时输入gcc file.c `pkg-config --libs --cflags gtk+-2.0` 注意`不是单引号,和--前均有一个字符 这样问题就结局啦

  10. 12、MyBatis教程之缓存

    13.缓存 简介 1.什么是缓存 [ Cache ]? 存在内存中的临时数据. 将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高 ...