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 ...
随机推荐
- Maximal Square 解答
Question Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1' ...
- Valid Palindrome 解答
Question Given a string, determine if it is a palindrome, considering only alphanumeric characters a ...
- Ajax 缓存问题
Ajax通过GET方式请求服务器数据,Microsoft Internet Explorer浏览器下,由于缓存问题,读取的数据非最新数据,解决问题方法如下: function getData(url, ...
- structs2标签
Struts2常用标签总结 一 介绍 1.Struts2的作用 Struts2标签库提供了主题.模板支持,极大地简化了视图页面的编写,而且,struts2的主题.模板都提供了很好的扩展性.实现了更好的 ...
- Android 官方文档:(二)应用清单 —— 2.26 <uses-permission>标签
syntax: <uses-permission android:name="string" android:maxSdkVersion="inte ...
- Multiscale Combinatorial Grouping 学习和理解源代码(一)
目标探测由于所做的最新研究.因此,这一领域的一般阅读文章.发现这篇文章,效果是比较新的比较好.在如此仔细研究.贴纸和共享.下面已经发布若干个连续的,分别对论文和代码进行大致地介绍,最后依据自己的实验对 ...
- 把Storyboard减轻的方法
把Storyboard减轻的方法 by 伍雪颖 UIViewController *secondStoryboard = [[UIStoryboard storyboardWithName:@&quo ...
- smaba服务的搭建
一. samba配置1. 什么是sambaSamba服务类似于windows上的共享功能,可以实现在Linux上共享文件,windows上访问,当然在Linux上也可以访问到.是一种在局域网上共享文件 ...
- idea maven 无法加载已经安装的模块
新建了一下maven项目,下面新建了一个模块,某一个模块clean install之后,别的模块虽然使用dependency标签引入了,但是仍然无法使用, 这个时候,应该重新建立一个项目,将原有项目的 ...
- nodejs实现接收Snmp的Trap消息
var assert = require('assert'); var ASN1 = { EOC: 0, Boolean: 1, Integer: 2, BitString: 3, OctetStri ...