fafu 1568 Matrix(二分匹配+二分)
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.
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 [, ^].
For each case, output Case #k: one line first, where k means the case number count from . Then output the answer.
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(二分匹配+二分)的更多相关文章
- ZOJ 3156 Taxi (二分匹配+二分查找)
题目链接:Taxi Taxi Time Limit: 1 Second Memory Limit: 32768 KB As we all know, it often rains sudde ...
- POJ 2289 多重二分匹配+二分 模板
题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值 下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说 ...
- BNUOJ 12756 Social Holidaying(二分匹配)
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memo ...
- hdu-2819.swap(二分匹配 + 矩阵的秩基本定理)
Swap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
随机推荐
- 2.x ESL第二章习题 2.8
题目 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3 ...
- [置顶] 九度笔记之 1434:今年暑假不AC
题目1434:今年暑假不AC 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:307 解决:180 题目描述: “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@# ...
- Volist标签 key值的使用
Volist标签是thinkphp框架view中常用到的一个标签.主要用于在模板中循环输出数据集或者多维数组.今天使用key属性时出了点问题,记录一下. volist标签(循环输出数据) 闭合 非闭合 ...
- Ubuntu学习-简单指令
查看是否安装了中文支持 locale -a 如果有 zh_CN.utf8 则表示系统已经安装了中文locale,如果没有则需要安装相应的软件包. 软件管理 apt ( Advanced Packagi ...
- jQuery -> end方法的使用方法
我们在对结果集使用find.filter等方法时,会改变结果集. 这样的改变原先结果集的方法被称作destructive jQuery method jQuery cookbook有例如以下定义: A ...
- 不定义JQuery插件,不要说会JQuery[转载]
http://www.cnblogs.com/xcj26/p/3345556.html 不定义JQuery插件,不要说会JQuery 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页 ...
- 一个操作EXCEL的C#类ExcelUtils
近期在公司里一直从事服务类的工作,涉及到非常多excel的处理.部分工作内容是每天反复的,仅仅是每天的数据不同而已.我遇到的一个问题是客户每天发送的几种数据有些excel中的字段顺序是一致的,有些是不 ...
- java学习之i/o
基本的输入输出 这里有两种方法,其中一种被注释了,可以换着注释后测试一遍 class TestSystem { public static void main(String[] args) { /* ...
- Appium项目搭建 For windows
1.appium又安装了最新版本,更新了,1.4.16.1,然后整理电脑的时候发现自动更新的时候不是在原来的地方进行覆盖,所以就重新安装了一遍,注意需要看下环境变量是否配置了(用户变量:C:\Appi ...
- 使用CSC.EXE编译第一个HELLO WORLD
坐的没事,下了个C#2008,看帮助文件写了个HELLO.CS的源文件: //hello.cs //Show "Hello Word!" using system; class h ...