【二分图最大匹配】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 ...
随机推荐
- fputcsv导出大量数据
<?php set_time_limit(0); ini_set('memory_limit', '128M'); $fileName = date('YmdHis', time()); hea ...
- [转]Maven与nexus关系
开始在使用Maven时,总是会听到nexus这个词,一会儿maven,一会儿nexus,当时很是困惑,nexus是什么呢,为什么它总是和maven一起被提到呢? 我们一步一步来了解吧. 一.了解Mav ...
- python全栈开发day80--评论楼、评论树
内容总结: 1. 内容回顾 1. 内容回顾 1.评论 1. 展示评论 1. 评论楼(Django模板语言渲染) 1. 从后端查询出所有的评论 2. 如果有父评论就展示父评论 2. 评论树 通过ajax ...
- Python_函数_参数
def 是函数的关键字,Python解释器一旦执行到def,默认不执行 def li(): n = 8 n +=1 print(n) li() li2 = li li2() 结果: 9 9 ret ...
- 2018牛客网暑假ACM多校训练赛(第四场)E Skyline 线段树 扫描线
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round4-E.html 题目传送门 - https://www.no ...
- 数据特征分析:3.统计分析 & 帕累托分析
1.统计分析 统计指标对定量数据进行统计描述,常从集中趋势和离中趋势两个方面进行分析 集中趋势度量 / 离中趋势度量 One.集中趋势度量 指一组数据向某一中心靠拢的倾向,核心在于寻找数据的代表值或中 ...
- 062 SparkStream内部原理
1.DStream 内部是一系列的RDD组成的,每个RDD与RDD的产生时间形成一个pair保存在内存中(下面有) RDD包含了对应时间段的所有block数据. 2.DStream下的方法 /** T ...
- mysql order by多个字段
Mysql order by 多字段排序 mysql单个字段降序排序: select * from table order by id desc; mysql单个字段升序排序: select * fr ...
- 搭建本地maven库(nexus服务器)
第一步,下载https://www.sonatype.com/download-oss-sonatype 别下3.x版本,下2.x版本 第二步,解压,在bin目录下执行cmd命令,nexus inst ...
- SPOJ RPLN (模板题)(ST算法)【RMQ】
<题目链接> 题目大意:给你一段序列,进行q次区间查询,每次都输出询问区间内的最小值. 解题分析: RMQ模板题,下面用在线算法——ST算法求解.不懂ST算法的可以看这篇博客 >& ...