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 ...
随机推荐
- ADO.NET改进版
ADO.NET从概念上来说是指定义一种与数据源进行交互的面向对象类库.类库即类的集合,也就是说ADO.NET主要是提供一了一些实现与数据源进行交互的一些类和接口. 其实就我个人看来,我觉得ADO.NE ...
- OC中NSString 的常用方法
NSString *str1 = @"BeiJing"; NSString *str2 = @"beijing"; //全部转为大写 NSLog(@" ...
- asp.net 导出excel文件
之前做过winfrom程序的导出excel文件的功能,感觉非常简单.现在试着做asp.net中导出excel的功能,之前用的是Microsoft.Office.Interop.Excel这个对象来实现 ...
- Android学习之sqlite与listview
在android系统中使用的是sqlite数据库,前面的简易登录系统已经讲述了数据库的应用.本例的重点是实现数据库与listview的绑定.demo的数据是将个人的信息绑定到listview中,并存在 ...
- android开发MD5加密工具类(一)
MD5加密工具类整理: package com.gzcivil.utils; import java.io.UnsupportedEncodingException; import java.secu ...
- 01js高级_1
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- hive 函数学习
NAME PRICE ---- ----- AAA 1.59 AAA 2.00 AAA 0.75 BBB 3.48 BBB 2.19 BBB 0.99 BBB 2.50 I would like to ...
- iOS self和super的区别
self和super的区别 #import <Foundation/Foundation.h> 首先先写两个类 fist和two,two继承fist类 @interface First:N ...
- ARP网关占用
30网段已经发生了2次ARP了 排查方法:我直去核心交换机直连镜像口,用wireshark抓包,过滤出ARP的包 发现的确有ARP的攻击,因为没有统计公司电脑和无线路由的MAC地址,所以只能一个个把无 ...
- c# 另存为excel
去网上找了一下 看了一个比较简单的新建excel然后另存为. 要引用Microsoft.Office.Interop.Excel命名空间,如果没有的话 ,百度比我懂. 直接付代码: Microsof ...