毒瘤3

TimeLimit:1000MS  MemoryLimit:256MB
64-bit integer IO format:%lld
 
Problem Description

字节跳动有n款产品,和m  (m>=n)种不同的类型的客户。产品的价值由客户类型决定,第i种产品对于第j种个客户的价为值Aij.

形成一个n*m的价值矩阵。你需要为每款产品各选择一种要适应的客户。同时为最大化覆盖客户群体,且这些产品的适应客户

必须不同。问在为每个产品分配好客户类型后,把这些产品中价值第k大的数字最小能为多少。

Input

第一行给出三个整数N,M,K(1<=K<=N<=M<=250,1<=Aij<=1e9)

接下来N行,每行M个数字,用来描述每个产品对m种客户的价值

20%的数据n+m<=20

40%的数据n+m<=40

100%的数据n<=250

Output

输出价值第k大的数字的最小值

SampleInput
3 4 2
1 5 6 6
8 3 4 3
6 8 6 3
SampleOutput
3

思路:显然肯定存在这个k,且肯定存在至少n - k + 1个匹配的权值比第k大的小。那么我们直接二分这个第k大的权值,然后把权值小于这个值的边建边跑最大匹配,如果至少有n - k + 1个匹配,那么显然这个值是可能的(不一定存在k-1个比他大)。根据题意第k大一定存在,那么最后二分出来的也一定存在。

代码:

#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = + ;
const int INF = 0x3f3f3f3f;
int linker[maxn];
bool used[maxn];
int n, m, k, cnt;
struct Edge{
int to, next;
int u, v, w;
bool operator < (const Edge &x) const{
return w < x.w;
}
}edge[maxn * maxn], g[maxn * maxn];
int head[maxn], tot;
void addEdge(int u, int v){
g[tot].to = v;
g[tot].next = head[u];
head[u] = tot++;
}
bool dfs(int u){
for(int i = head[u]; i != -; i = g[i].next){
int v = g[i].to;
if(!used[v]){
used[v] = true;
if(linker[v] == - || dfs(linker[v])){
linker[v] = u;
return true;
}
}
}
return false;
}
int hungry(){
int res = ;
memset(linker, -, sizeof(linker));
for(int u = ; u <= n; u++){
memset(used, false, sizeof(used));
if(dfs(u)) res++;
}
return res;
}
bool can(int mid){
memset(head, -, sizeof(head));
tot = ;
for(int i = ; i <= cnt; i++){
if(edge[i].w <= mid){
addEdge(edge[i].u, edge[i].v);
}
else break;
}
return (hungry() >= n - k + );
}
int main(){
scanf("%d%d%d", &n, &m, &k);
cnt = ;
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++){
scanf("%d", &edge[++cnt].w);
edge[cnt].u = i, edge[cnt].v = j;
}
}
sort(edge + , edge + cnt + );
int l = , r = 1e9, ans;
while(l <= r){
int mid = (l + r) >> ;
if(can(mid)){
ans = mid;
r = mid - ;
}
else{
l = mid + ;
}
}
printf("%d\n", ans);
return ;
}

FJUT 毒瘤3(二分 + 最大匹配)题解的更多相关文章

  1. hdu2063 匈牙利算法 二分最大匹配模版题

    过山车 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java class na ...

  2. POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))

    题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...

  3. hdu 2444 交叉染色判断二分图+二分最大匹配

    /*1A 31ms*/ #include<stdio.h> #include<string.h> #define N 300 int n; struct node { int ...

  4. [codeforces 852 D] Exploration Plan 解题报告 (二分+最大匹配)

    题目链接:http://codeforces.com/problemset/problem/852/D 题目大意: 有V个点,N个队伍,E条边,经过每条边有个时间,告诉你初始N个队伍的位置,求至少有K ...

  5. loj 1150(spfa预处理+二分+最大匹配)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26864 思路:首先是spfa预处理出每个'G'到'H'的最短距离, ...

  6. poj1274 The Perfect Stall (二分最大匹配)

    Description Farmer John completed his new barn just last week, complete with all the latest milking ...

  7. Treasure Exploration(二分最大匹配+floyd)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 7455   Accepted: 3 ...

  8. POJ 1743 Musical Theme(后缀数组 + 二分)题解

    题意:一行数字,定义如下情况为好串: 1.连续一串数字,长度大于等于5 2.这行数字中多次出现这串数字的相似串,相似串为该串所有数字同加同减一个数字,如 1 2 3 和 5 6 7 3.至少有一个相似 ...

  9. POJ 2785 4 Values whose Sum is 0 (二分)题解

    思路: 如果用朴素的方法算O(n^4)超时,这里用折半二分.把数组分成两块,分别计算前后两个的和,然后枚举第一个再二分查找第二个中是否有满足和为0的数. 注意和有重复 #include<iost ...

随机推荐

  1. [7] Windows内核情景分析---线程同步

    基于同步对象的等待.唤醒机制: 一个线程可以等待一个对象或多个对象而进入等待状态(也叫睡眠状态),另一个线程可以触发那个等待对象,唤醒在那个对象上等待的所有线程. 一个线程可以等待一个对象或多个对象, ...

  2. 16. 3Sum Closest(双指针)

    Given an array nums of n integers and an integer target, find three integers in nums such that the s ...

  3. Vue系列之 => 使用钩子函数的第二个参数传参

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. tetrahedron (公式)

    我是直接搬运了某大佬的代码,毕竟我不清楚如何计算这个东西. 其中四点共面的求法就是体积为0,然后圆心和半径就公式了. #include<cstdio> #include<iostre ...

  5. Java基础语法(一 )

    一.关键字 关键字概述 被Java语言赋予特定含义的单词 关键字特点 组成关键字的字母全部小写 关键字注意事项 goto和const作为保留字存在,目前并不使用 关键字单词 用于定义数据类型的关键字 ...

  6. Java重排序

    重排序数据依赖性 如果两个操作访问同一个变量,且这两个操作中有一个为写操作,此时这两个操作之间就存在数据依赖性.数据依赖分下列三种类型: 名称 代码示例 说明 写后读 a = 1;b = a; 写一个 ...

  7. PIVOT(透视转换)和UNPIVOT(逆透视转换)

    一.原数据状态 二.手动写透视转换1 三.手动写透视转换2 四.PIVOT(透视转换)和UNPIVOT(逆透视转换)详细使用 使用标准SQL进行透视转换和逆视转换 --行列转换 create tabl ...

  8. 专题8:javascript函数详解

    函数是一段可以反复调用的代码块.函数还能接受输入的参数,不同的参数会返回不同的值. 函数的声明 JavaScript 有三种声明函数的方法. (1)function 命令 function命令声明的代 ...

  9. SpringMVC MultiActionController 默认方法名解析器

    MultiActionController默认方法名解析器是指在请求的地址中加入指定方法名称 MultiActionController类具有一个属性methodNameResolver,方法名解析器 ...

  10. php 使用table方式导出excel文件

    这些天在使用PHPExcel导出数据时,5000条数据竟然挂了.后来跟同事聊聊,有些明悟,PHPExcel做了很多处理,我在这里理解为渲染,就会暂用过多的空间,‘膨胀’的空间导致内存暂用过大,就挂了. ...