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 ...
随机推荐
- 【转】RTSP流理解
rtsp是使用udp还是tcp,是跟服务器有关,服务器那边说使用udp,那就使用udp,服务器说使用tcp那就使用tcp rtsp客户端的创建: 1.建立TCP socket,绑定服务器ip,用来传送 ...
- Sublime Text 3 乱码解决
步骤: 在Sublime Text里,按ctrl+`,打开Console,一次性输入如下代码: import urllib.request,os; pf = 'Package Control.subl ...
- linux 在批处理中,完整路径有空格的处理方式(加引號)
cp -f E:/XML_EDITOR/xmleditor25/xmleditor/Editor_UIOuterCtrl/TraceViewDlg.cpp E:/XML_EDITOR/'XMLEdit ...
- MVC4中 jquery validate 不用submit方式验证表单或单个元素
正确引入MVC4 jquery验证的相关文件 <script src="/Scripts/jquery-1.4.4.js"></script> <sc ...
- Reflux 使用教程
Reflux是根据React的flux创建的单向数据流类库.Reflux的单向数据流模式主要由actions和stores组成.例如,当组件list新增item时,会调用actions的某个方法(如a ...
- 【温故而知新】Tcp/Ip协议——总览
Tcp/Ip协议 一.概念 “三网”:即电信网络.有线电视网络和计算机网络 标准(Standards) 描述了协议的规定,设定了最简的性能集. 协议(Protocol) 网络设备用于交换信息的系列规则 ...
- PHP.INI常用设置一览表(持续更新)
在编程的过程中遇到或发现的问题,会持续的更新: 1. 打破var_dump的显示瓶颈 php开发环境里,安装了xdebug模块后,var_dump()输出的结果将比较易于查看,但默认情况下,var_d ...
- HNOI2004 宠物收养所 解题报告
首先读完这题第一印象,是个裸题,很高兴.其次在打完代码之后,第二印象,很恶心,Treap的代码太长了,我今天下午敲了三遍,手都麻了. 废话不多说,正题.其实这个题不难,有几个点是很好的,首先,他的a值 ...
- Java API设计CheckList
API设计原则:正确.好名.易用.易学.够快.够小.但我们从来不缺原则,〜〜〜 Interface 1.The Importance of Being Use Case Oriented,一个接口应当 ...
- 记微信开发(自定义回复&关注回复)
记微信开发(自定义回复&关注回复) 记微信开发(自定义回复&关注回复) code: <?php/** * wechat php test *///define your toke ...