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 ...
随机推荐
- nginx监听端口和反向代理端口的权限问题
Linux的SELinux安全性控制除作用于文件系统外还作用于端口,这使得那些作为服务启动的进程只能在规定的几个端口上监听.为叙述方便我们称之为受控端口. nginx监听端口 要查看当前有哪些受控端口 ...
- UESTC_邱老师看电影 2015 UESTC Training for Dynamic Programming<Problem F>
F - 邱老师看电影 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- 剑指offer-面试题17.合并两个排序的链表
题目:输入两个递增的排序的链表,合并这两个链表并使新链表中的节点仍然是 按照递增排序的.例如链表1链表2合并为链表3. List1:->->-> List2:->->-& ...
- FZU1862(线段树 或者 DP)
Problem 1862 QueryProblem Accept: 100 Submit: 249Time Limit: 2000 mSec Memory Limit : 32768 KB ...
- 456. 132 Pattern
456. 132 Pattern Given an array of integers a1, a2, a3-an, judge if there exists the 132 pattern. 13 ...
- C语言结构体的内存对齐问题
在C语言开发当中会遇到这样的情况: #include <stdio.h> struct test { int a; char b; }; int main(int argc, const ...
- django 启动和请求
Django运行方式 调试模式 直接 python manage.py runserver python manage.py runserver python manage.py runserver ...
- 中秋佳节--理解Enum枚举
一.Enum枚举的作用 1.使用枚举可以限定取值范围,枚举中定义的每个常量都可以理解为对象: Eg: Public enum Color{ RED, GREEN,BULE; } 说明:RED实际上就表 ...
- [Python笔记][第二章Python序列-复杂的数据结构]
2016/1/27学习内容 第二章 Python序列-复杂的数据结构 堆 import heapq #添加元素进堆 heapq.heappush(heap,n) #小根堆堆顶 heapq.heappo ...
- NDK下 将Platinum SDK 编译成so库 (android - upnp)
Platinum UPnP SDK 是一个跨平台的C++库,利用该库,可以很容易就构建出DLNA/UPnP控制点(DLNA/UPnP Control Point)和DLNA/UPnP设备(DLNA/U ...