Description:
 

You are given a matrix which is n rows m columns ( <= n <= m <= ). You are supposed to choose n elements, there is no more than  element in the same row and no more than  element in the same column. What is the minimum value of the K_th largest in the n elements you have chosen.
 
Input:
 
First line is an integer T (T ≤ ), the number of test cases. At the beginning of each case is three integers n, m, K,  <= K <= n <= m <= .
Then n lines are given. Each line contains m integers, indicating the matrix.
All the elements of the matrix is in the range [, ^].
 
Output:
 
For each case, output Case #k: one line first, where k means the case number count from . Then output the answer.
 
Sample Input:
 

 
Sample Output:
 
Case #:
Case #:

二分枚举答案,如果a[i][j]<=mid则建一条xi->yj的边,然后对二分图跑最大匹配,如果最大匹配数>=n-k+1,则ans<=mid,否则ans>mid

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 106
#define inf 1e10
int n,m,k;
int mp[N][N];
int cnt[N][N];
int vis[N];
int link[N];
vector<int> v; void build_map(int mid){
memset(cnt,,sizeof(cnt));
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(mp[i][j]<=mid){
cnt[i][j]=;
}
}
}
} bool dfs(int u){
for(int i=;i<m;i++){
if(!vis[i] && cnt[u][i]){
vis[i]=;
if(link[i]==- || dfs(link[i])){
link[i]=u;
return true;
}
}
}
return false;
}
bool solve(int mid){
build_map(mid);
memset(link,-,sizeof(link));
int ans=;
for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
if(dfs(i)){
ans++;
}
} if(ans>=(n-k+)) return true;
return false; }
int main()
{
int ac=;
int t;
scanf("%d",&t);
while(t--){
memset(mp,,sizeof(mp));
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++){
for(int j=;j<m;j++){
scanf("%d",&mp[i][j]);
}
}
int low=;
int high=inf;
while(low<high){
int mid=(low+high)>>;
if(solve(mid)){
high=mid;
//ans=mid;
}else{
low=mid+;
}
}
printf("Case #%d: ",++ac);
printf("%d\n",low); }
return ;
}

fafu 1568 Matrix(二分匹配+二分)的更多相关文章

  1. ZOJ 3156 Taxi (二分匹配+二分查找)

    题目链接:Taxi Taxi Time Limit: 1 Second      Memory Limit: 32768 KB As we all know, it often rains sudde ...

  2. POJ 2289 多重二分匹配+二分 模板

    题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值 下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说 ...

  3. BNUOJ 12756 Social Holidaying(二分匹配)

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memo ...

  4. hdu-2819.swap(二分匹配 + 矩阵的秩基本定理)

    Swap Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  6. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  7. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  8. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  9. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

随机推荐

  1. 【HDU 5510 Bazinga】字符串

    2015沈阳区域赛现场赛第2题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:给定一个由字符串组成的序列,一共n个元素,每个元素是一个不 ...

  2. poj 1753 Flip Game(bfs状态压缩 或 dfs枚举)

    Description Flip game squares. One side of each piece is white and the other one is black and each p ...

  3. poj 3311 Hie with the Pie(状态压缩dp)

    Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he star ...

  4. hdu 5493 Queue(线段树)

    Problem Description N people numbered to N are waiting in a bank for service. They all stand in a qu ...

  5. UGUI Image控件

    今天一起学习Image控件O(∩_∩)O~ 介绍一下基本的属性 Source:Image:               指定图片源, 图片设置2DSprite(2D and UI)格式Color:   ...

  6. java各公司笔试题集1

    IBM笔试题 注:IBM笔试题一小时之内完成,题目全部用英文描述,这里用中文表述 一.名词解释 1.Eclipse 2.J2EE 3.EJB 4.Ajax 5.Web service 二.找出以下代码 ...

  7. [置顶] Android开发实战记录(三)---HelloWorld

    1.新建Android项目,选择Android Project,然后Next 2.填写项目名称HelloWorld然后next,这里注意下,Java开发的命名规范 3.选择Android SDK版本, ...

  8. js面向对象编程:if中能够使用那些作为推断条件呢?

       在全部编程语言中if是最长用的推断之中的一个.但在js中究竟哪些东西能够在if中式作为推断表达式呢? 比如怎样几行,仅仅是少了一个括号.真假就全然不同.究竟表示什么含义呢 var obj={}; ...

  9. Riak VClock

    Riak VClock 关于向量时钟的概念.在这里就多讲了,大家能够參照一下Dynamo的论文了解一下,向量时钟在分布式主要用于解决一致性性问题.能够和CRDTs一起看. 以下的源码是參照riak中的 ...

  10. cloudstack4.4新增功能前瞻

    cloudstack4.4.0新功能前瞻 转载请注明地址:http://blog.csdn.net/zt689/article/details/37698989 1.   cloudstack4.4. ...