这道题是让求派出机器人的最少数量,乍一看以为是简单的求最小路径覆盖,后来发现错了,因为有的点可以走多次,而二分中每个点只能走一次,所以要先用floyd进行传递闭包,然后用二分

#include<stdio.h>
#include<string.h>
#define N 505 int match[N],visit[N];
int n,m;
int g[N][N];
int DFS(int u)
{
int i;
for(i=;i<=n;i++) if(!visit[i]&&g[u][i])
{
visit[i]=;
if(match[i]==-||DFS(match[i]))
{
match[i]=u;
return ;
}
}
return ;
}
int maxMatch()
{
memset(match,-,sizeof(match));
int ans=,i;
for(i=;i<=n;i++)
{
memset(visit,,sizeof(visit));
if(DFS(i)) ans++;
}
return ans;
}
void Floyd()
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(g[i][k] && g[k][j])
g[i][j]=;
}
int main()
{
int a,b;
while(scanf("%d%d",&n,&m))
{
memset(g,,sizeof(g));
if((n+m)==)
break;
for(int i=;i<m;i++)
{
scanf("%d%d",&a,&b);
g[a][b]=;
}
Floyd();
printf("%d\n",n-maxMatch());
}
return ;
}

poj2459 Treasure Exploration (闭包+二分)的更多相关文章

  1. poj 2594 Treasure Exploration (二分匹配)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6558   Accepted: 2 ...

  2. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

  3. Treasure Exploration(二分最大匹配+floyd)

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

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

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

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

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

  6. POJ2594 Treasure Exploration

    Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8193   Accepted: 3358 Description Have ...

  7. POJ 2594 Treasure Exploration(最小路径覆盖变形)

    POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...

  8. POJ Treasure Exploration 【DAG交叉最小路径覆盖】

    传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K To ...

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

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

随机推荐

  1. SQLServer中临时表与表变量的区别分析【转】

    在实际使用的时候,我们如何灵活的在存储过程中运用它们,虽然它们实现的功能基本上是一样的,可如何在一个存储过程中有时候去使用临时表而不使用表变量,有时候去使用表变量而不使用临时表呢? 临时表 临时表与永 ...

  2. jQuery基础---Ajax基础教程

    jQuery基础---Ajax基础 内容提纲: 1.Ajax 概述 2.load()方法 3.$.get()和$.post() 4.$.getScript()和$.getJSON() 5.$.ajax ...

  3. myql 注意事项

    在[mysqld]下加入一行:lower_case_table_names=1,1为不区分大小写,0是区分大小写...并/etc/init.d/mysql restart即可...

  4. C++中数字与字符串之间的转换,别人的,

    C++中数字与字符串之间的转换   1.字符串数字之间的转换 (1)string --> char *   string str("OK");   char * p = st ...

  5. (Qt 翻译) QGLAbstractScene

    QGLAbstractScene Class Reference #include <QGLAbstractScene> This class was introduced in Qt3D ...

  6. 关于sql 外键的讨论。

    外键是否采用看业务应用场景,以及开发成本的,大致列下什么时候适合,什么时候不适合使用: 1. 互联网行业应用不推荐使用外键: 用户量大,并发度高,为此数据库服务器很容易成为性能瓶颈,尤其受IO能力限制 ...

  7. Android 信鸽推送通知栏不显示推送的通知

    使用信鸽推送,却怎么也没反应.经过查看log发现确实是收到了推送过来的消息了,其中有这么一行: W/dalvikvm(23255): VFY: unable to resolve virtual me ...

  8. nginx解决502错误

    添加一个域名绑定,突然服务器就挂了.由于是接受项目,没看过服务器配置.结果nginx和mysql 都跑不起来. 平滑启动nginx失败. 检查/usr/local/nginx/sbin/nginx - ...

  9. doT.js 模板引擎的使用

    dot.js是一个模板框架,在web前端使用. dot.js作为模板引擎, 主要的用途就是,在写好的模板上,放进数据,生成含有数据的html代码. 这是很简单的web前端模板框架, 简单说几个东西,你 ...

  10. Java之线程的生命周期

    在Java中,线程有5中不同状态,分别是:新建(New).就绪(Runable).运行(Running).阻塞(Blocked)和死亡(Dead).它们之间的转换图如下: 上图有一个例外,调用yiel ...