【二分图最大匹配】Bullet @山东省第九届省赛 B
时间限制: 6 Sec 内存限制: 128 MB
题目描述
In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an n × n map, and there are monsters in some grids. Each monster has an experience. As a master, however, Shino has a strange self-restrain. She would kill at most one monster in a column, and also at most one in a row. Now she wants to know how to get max experience, under the premise of killing as many monsters as possible.
输入
The first line contains an integer n
Then n lines follow. In each line there are n integers, and Aij represents the experience of the monster at grid(i,j). If Aij=0, there is no monster at grid(i,j).
输出
One integer, the value of max experience.
样例输入
2
2 0
1 8
样例输出
2
每行每列最多取一个数,构成的集合在满足元素数量最多的前提下,最小值最大。
最小值增大时,可匹配边的数量减少,所以最大匹配可能减小,于是可以二分最小值,每次求图中权值大于最小值的边的最大匹配。
#define IN_LB() freopen("C:\\Users\\acm2018\\Desktop\\in.txt","r",stdin)
#define OUT_LB() freopen("C:\\Users\\acm2018\\Desktop\\out.txt","w",stdout)
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
struct edge {
int v,w,nex;
} ed[maxn*maxn];
int head[maxn],cnt,n,vis[maxn],match[maxn];
void addedge(int u,int v,int w) {
cnt++;
ed[cnt].v = v;
ed[cnt].w = w;
ed[cnt].nex = head[u];
head[u] = cnt;
}
bool dfs(int u,int limit) {
for(int i=head[u]; i; i=ed[i].nex) {
int v = ed[i].v;
if(ed[i].w>=limit&&!vis[v]) {
vis[v] = 1;
if(!match[v]||dfs(match[v],limit)) {
match[v] = u;
return true;
}
}
}
return false;
}
int judge(int limit) {
memset(match,0,sizeof match);
int cnt = 0;
for(int i=1; i<=n; i++) {
memset(vis,0,sizeof vis);
if(dfs(i,limit))
cnt++;
}
return cnt;
}
int main() {
// IN_LB();
scanf("%d",&n);
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
int weight;
scanf("%d",&weight);
addedge(i,j,weight);
}
}
int ans = judge(1);
int res = 0,base = 1<<30;
while(base>=1) {
if(judge(res+base) == ans) {
res += base;
} else
base >>= 1;
}
printf("%d\n",max(1,res));
return 0;
}
【二分图最大匹配】Bullet @山东省第九届省赛 B的更多相关文章
- 【二分图带权匹配】Anagram @山东省第九届省赛 A
题目描述 Orz has two strings of the same length: A and B. Now she wants to transform A into an anagram o ...
- 【容斥】Four-tuples @山东省第九届省赛 F
时间限制: 10 Sec 内存限制: 128 MB 题目描述 Given l1,r1,l2,r2,l3,r3,l4,r4, please count the number of four-tuples ...
- nyoj1273 河南省第九届省赛_"宣传墙"、状压DP+矩阵幂加速
宣传墙 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做 ...
- NYOJ 1272 表达式求值 第九届省赛 (字符串处理)
title: 表达式求值 第九届省赛 nyoj 1272 tags: [栈,数据结构] 题目链接 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表 ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- SD第九届省赛B题 Bullet
Bullet Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description In G ...
- 蓝桥杯第九届省赛 sscanf(),str.c_str()函数的使用
标题:航班时间 [问题背景]小h前往美国参加了蓝桥杯国际赛.小h的女朋友发现小h上午十点出发,上午十二点到达美国,于是感叹到“现在飞机飞得真快,两小时就能到美国了”. 小h对超音速飞行感到十分恐惧.仔 ...
- ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛
Lazy Salesgirl Time Limit: 5 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...
- ZOJ 3601 Unrequited Love 浙江省第九届省赛
Unrequited Love Time Limit: 16 Seconds Memory Limit: 131072 KB There are n single boys and m si ...
随机推荐
- [转]java位运算(1)
http://blog.csdn.net/xiaochunyong/article/details/7748713 Java提供的位运算符有:左移( << ).右移( >> ) ...
- 通过impala更改Kudu表属性
开发人员可以通过更改表的属性来更改 Impala 与给定 Kudu 表相关的元数据.这些属性包括表名, Kudu 主地址列表,以及表是否由 Impala (内部)或外部管理. Rename an Im ...
- js中的new Option默认选中
new Option("文本","值",true,true).后面两个true分别表示默认被选中和有效! //js默认选中 var sel = document ...
- Spring(四)使用注解注入Bean
注解简单介绍 是代码里面的特殊标记,使用注解完成功能. 注解写法@ 注解名称(属性名=属性值). 注解可以作用在类.方法.属性上面. 使用流程: 在ApplicationContext.xml中开启注 ...
- Working out(DP)
题目描述: 题意: 有n*m个格子, 走过一个格子可以得到相应的分数. A 从(1,1)沿 下 或 右 走到(n,m) B 从(n,1)沿 上 或 右 走到(1,m) 两人路径有且只能有一个格子重合( ...
- POJ 3169 Layout 【差分约束】+【spfa】
<题目链接> 题目大意: 一些母牛按序号排成一条直线.有两种要求,A和B距离不得超过X,还有一种是C和D距离不得少于Y,问可能的最大距离.如果没有最大距离输出-1,如果1.n之间距离任意就 ...
- JavaScript函数、闭包、原型、面向对象
JavaScript函数.闭包.原型.面向对象 断言 单元测试框架的核心是断言方法,通常叫assert(). 该方法通常接收一个值--需要断言的值,以及一个表示该断言目的的描述. 如果该值执行的结果为 ...
- MySQL_时间戳处理
时间戳查询当天范围的数据 date(FROM_UNIXTIME(createAt, '%Y-%m-%d %H:%i:%s')) = CURDATE() 例: SELECT * FROM q_compa ...
- 洛谷 P2814 家谱(gen)
题目背景 现代的人对于本家族血统越来越感兴趣. 题目描述 给出充足的父子关系,请你编写程序找到某个人的最早的祖先. 输入输出格式 输入格式: 输入由多行组成,首先是一系列有关父子关系的描述,其中每一组 ...
- [NOIp2018提高组]货币系统
[NOIp2018提高组]货币系统 题目大意: 有\(n(n\le100)\)种不同的货币,每种货币的面额为\([1,25000]\)之间的一个整数.若两种货币系统能够组合出来的数是相同的的,那我们就 ...