poj2459 Treasure Exploration (闭包+二分)
这道题是让求派出机器人的最少数量,乍一看以为是简单的求最小路径覆盖,后来发现错了,因为有的点可以走多次,而二分中每个点只能走一次,所以要先用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 (闭包+二分)的更多相关文章
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ...
- Treasure Exploration(二分最大匹配+floyd)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7455 Accepted: 3 ...
- POJ2594 Treasure Exploration(最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8550 Accepted: 3 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ2594 Treasure Exploration
Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8193 Accepted: 3358 Description Have ...
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...
- POJ Treasure Exploration 【DAG交叉最小路径覆盖】
传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K To ...
- POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 9794 Accepted: 3 ...
随机推荐
- ROW_NUMBER() OVER函数的基本用法用法【转】
语法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN) 简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW ...
- Fault Diagnosability Infrastructure Overview
Fault Diagnosability Infrastructure Overview The fault diagnosability infrastructure aids in prevent ...
- css float笔记
float 1.破坏性,让设置了float属性的元素脱离文档流 2.包裹性:div设置了float之后,其宽度会自动调整为包裹住内容宽度,而不是撑满整个父容器.如果没有包裹性,如何实现文字环绕(flo ...
- js获取网页高度和宽度(备份)
网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWi ...
- JavaScript学习笔记——JS中的变量复制、参数传递和作用域链
今天在看书的过程中,又发现了自己目前对Javascript存在的一个知识模糊点:JS的作用域链,所以就通过查资料看书对作用域链相关的内容进行了学习.今天学习笔记主要有这样几个关键字:变量.参数传递.执 ...
- Android 获取 root权限
在进行android 开发的时候,经常用真机进行调试,有时候需要把手机中的sqlite数据复制出来.这时候就需要获取手机的root权限.通过 adb shell 命令可以获取权限. 1. 运行cmd ...
- android欢迎页源码
直接上源码: import android.app.Activity; import android.content.Intent; import android.os.Bundle; import ...
- (三)Android中Intent概念及应用
一.显示Intent startActivity(new Intent(MainActivity.this,BAty.class)); 显示Intent直接指定要启动的Intent类 注意自己通过创建 ...
- OC——NSString的常用方法
NSString *str1 = @"BeiJing"; NSString *str2 = @"beijing"; //全部转为大写 NSLog(@" ...
- 图的深度优先遍历(DFS) c++ 非递归实现
深搜算法对于程序员来讲是必会的基础,不仅要会,更要熟练.ACM竞赛中,深搜也牢牢占据着很重要的一部分.本文用显式栈(非递归)实现了图的深度优先遍历,希望大家可以相互学习. 栈实现的基本思路是将一个节点 ...