[luogu4251 SCOI2015] 小凸玩矩阵 (二分图最大匹配)
Description

Input

Output
输出包含一行,为选出的 n 个数中第 k 大数的最小值。
Sample Input
输入样例1:
2 3 1
1 2 4
2 4 1
输入样例2:
3 4 2
1 5 6 6
8 3 4 3
6 8 6 3
Sample Output
输出样例1:
1
输出样例2:
3
HINT

Solution
k大值最小,显然可以二分
对于mid若它是第k大数,则一定存在>=n-k-1个比mid小的数
用最大匹配的结果和n-k比较即可
Code
//By Menteur_Hxy
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define int long long
#define F(i,a,b) for(register int i=(a);i<=(b);i++)
#define E(i,u) for(register int i=head[u];i;i=nxt[i])
#define ins(a,b,c) add(a,b,c),add(b,a,0)
#define add(a,b,c) nxt[++cnt]=head[a],to[cnt]=b,cst[cnt]=c,head[a]=cnt
using namespace std;
int read() {
int x=0,f=1; char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
return x*f;
}
const int N=1010,INF=0x3f3f3f3f;
int n,m,k,ans,cnt,S,T;
int nxt[N*N],to[N*N],cst[N*N],head[N<<1],cur[N*N];
int da[N][N],dis[N<<1],que[N<<1];
bool bfs() {
memset(dis,0,sizeof(dis));
int h=0,t=1; que[++h]=S; dis[S]=1;
while(h<=t) {
int u=que[h++];
// cout<<u<<" "<<dis[u]<<endl;
E(i,u) if(!dis[to[i]]&&cst[i]>0)
dis[to[i]]=dis[u]+1,que[++t]=to[i];
}
return dis[T]>0;
}
int dfs(int u,int flow) {
if(u==T) return flow;
int used=0;
for(register int &i=cur[u],v;i;i=nxt[i])
if(cst[i]>0&&dis[(v=to[i])]==dis[u]+1) {
// cout<<u<<" "<<v<<endl;
int tmp=dfs(v,min(flow-used,cst[i]));
// cout<<min(flow-used,cst[i])<<" "<<tmp<<endl;
cst[i]-=tmp; cst[i^1]+=tmp;
used+=tmp; if(used==flow) return flow;
}
if(!used) dis[u]=-1;
return used;
}
int dinic() {
int res=0;
while(bfs()) {
// cout<<dis[T]<<endl;
F(i,0,n+m+1) cur[i]=head[i];
res+=dfs(S,INF);
}
return res;
}
bool jud(int x) {
cnt=1;
memset(head,0,sizeof(head));
F(i,1,n) ins(S,i,1); F(i,1,m) ins(i+n,T,1);
F(i,1,n) F(j,1,m) if(da[i][j]<=x) ins(i,j+n,1);
int res=dinic();
return res>n-k;
}
signed main() {
// freopen("1.txt","r",stdin);
n=read(),m=read(),k=read();
S=0; T=n+m+1; ans=INF;
int l=INF,r=0;
F(i,1,n) F(j,1,m)
da[i][j]=read(),l=min(l,da[i][j]),r=max(r,da[i][j]);
while(l<=r) {
int mid=(l+r)>>1;
// cout<<mid<<endl;
if(jud(mid)) ans=min(ans,mid),r=mid-1;
else l=mid+1;
}
printf("%lld",ans);
return 0;
}
[luogu4251 SCOI2015] 小凸玩矩阵 (二分图最大匹配)的更多相关文章
- BZOJ 4443: [Scoi2015]小凸玩矩阵 二分图最大匹配+二分
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4443 题解: 二分答案,判断最大匹配是否>=n-k+1: #include< ...
- 【BZOJ4443】[Scoi2015]小凸玩矩阵 二分+二分图最大匹配
[BZOJ4443][Scoi2015]小凸玩矩阵 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个数字不能在同一行或 ...
- BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配
BZOJ_4443_[Scoi2015]小凸玩矩阵_二分+二分图匹配 Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个 ...
- 2018.06.30 BZOJ4443: [Scoi2015]小凸玩矩阵(二分加二分图匹配)
4443: [Scoi2015]小凸玩矩阵 Time Limit: 10 Sec Memory Limit: 128 MB Description 小凸和小方是好朋友,小方给小凸一个N*M(N< ...
- BZOJ 4443: [Scoi2015]小凸玩矩阵 最大流
4443: [Scoi2015]小凸玩矩阵 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4443 Description 小凸和小方是好 ...
- bzoj 4443 [Scoi2015]小凸玩矩阵 网络流,二分
[Scoi2015]小凸玩矩阵 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1564 Solved: 734[Submit][Status][Di ...
- 【bzoj4443】【[Scoi2015]小凸玩矩阵】二分+二分图最大匹配
(上不了p站我要死了,侵权度娘背锅) Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个数字不能在同一行或同一列,现小凸 ...
- bzoj 4443: [Scoi2015]小凸玩矩阵
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 149 Solved: 81[Submit][Status][Discuss] Description ...
- 【刷题】BZOJ 4443 [Scoi2015]小凸玩矩阵
Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个数字不能在同一行或同一列,现小凸想知道选出来的N个数中第K大的数字的最 ...
随机推荐
- web压力測试-Web Bench
1.web bench下载.地址:http://home.tiscali.cz/~cz210552/webbench.html 2.wen bench安装: [root@web111 tmp]#tar ...
- DirectX11 学习笔记8 - 最简单的光照
在上一个列子的基础上加了一个地面.这个地面是光照效果生成的. 看图: 先说明: 光照 须要重写一个 lightshader 就是光照的渲染器 // Define the input layout D ...
- Navicat Lite 提示Connection to mysql server on 10065
Navicat Lite 提示Connection to mysql server on 10065 验证过主要是防火墙问题 [root@014136251035 zhop]# vi /etc/sys ...
- hdu 2205(容斥原理)
Eddy's爱好 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- CPPCMS库在Windows下的使用
标题:CPPCMS库在Windows下的使用时间:2012-7作者:Kagula 环境:[1]WinXP SP3[2]VisualStudio2008 SP1[3]ZLib 1.2.7[4]PCRE ...
- 新建项目git clone
- Python入门 六、像个 Pythonista
pickle import pickle test_data = ['Save me!',123.456,True] f = file('test.data','w') pickle.dump(tes ...
- [Apple开发者帐户帮助]五、管理标识符(5)创建一个iCloud容器
您必须拥有一个或多个iCloud容器才能启用iCloud. 所需角色:帐户持有人或管理员. 在“ 证书”,“标识符和配置文件”中,从左侧的弹出菜单中选择操作系统. 在“标识符”下,选择“iCloud容 ...
- Git 和 Redis 的基本认识
一: Git 二: Redis
- ACM_名字的价值
名字的价值 Time Limit: 2000/1000ms (Java/Others) Problem Description: 集训终于开始了,参加集训的人很多,也就有很多名字,集训组织者发现了一件 ...