(二分匹配“匈牙利算法”)无题II --HDU --2236
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2236
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 105
#define INF 0xffffff ///匹配
///只需要用二分找一个区间,
///然后不断枚举这个区间是否可以达到最大匹配,
///一直二分到答案为止。 int G[N][N], ly[N];
int Max, Min, n;
bool used[N]; bool Find(int i)
{
for(int j=; j<=n; j++)
{
if(!used[j] && G[i][j]>=Min && G[i][j]<=Max)
{
used[j] = true;
if(!ly[j] || Find(ly[j]))
{
ly[j] = i;
return true;
}
}
}
return false;
} int XYL()
{
memset(ly, , sizeof(ly));
int ans = ; for(int i=; i<=n; i++)
{
memset(used, false, sizeof(used));
if(Find(i))
ans ++ ;
}
return ans;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i, j, MinL=INF, MaxR=-INF; scanf("%d", &n); for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
scanf("%d", &G[i][j]);
if(MinL > G[i][j]) MinL = G[i][j];
if(MaxR < G[i][j]) MaxR = G[i][j];
} int L=, R=MaxR-MinL, ans=; while(L <= R)
{
int Mid = (R+L)>>; for(i=; i<=MaxR-Mid; i++)
{
Min = i, Max = i+Mid;
if(XYL()==n) break;
} if(i<=MaxR-Mid)
{
ans = Mid;
R = Mid - ;
}
else L = Mid + ;
} printf("%d\n", ans);
}
return ;
}
(二分匹配“匈牙利算法”)无题II --HDU --2236的更多相关文章
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 【01染色法判断二分匹配+匈牙利算法求最大匹配】HDU The Accomodation of Students
http://acm.hdu.edu.cn/showproblem.php?pid=2444 [DFS染色] #include<iostream> #include<cstdio&g ...
- 无题II HDU - 2236 【二分图+二分答案】
题目 这是一个简单的游戏,在一个n*n的矩阵中,找n个数使得这n个数都在不同的行和列里并且要求这n个数中的最大值和最小值的差值最小. Input 输入一个整数T表示T组数据. 对于每组数据第一行输入一 ...
- 无题II hdu 2236(二分枚举区间)
分析:只需要用二分找一个区间,然后不断枚举这个区间是否可以达到最大匹配,一直二分到答案为止. 代码: =============================================== ...
- hdu 2063 (二分匹配 匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU-3729 二分匹配 匈牙利算法
题目大意:学生给出其成绩区间,但可能出现矛盾情况,找出合理组合使没有说谎的人尽可能多,并按maximum lexicographic规则输出组合. //用学生去和成绩匹配,成绩区间就是学生可以匹配的成 ...
- 【HDU 2255】奔小康赚大钱 (最佳二分匹配KM算法)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)
The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...
随机推荐
- 概率论与数理统计 Q&A:
--------------------------------- 大数定律:大量样本数据的均值(样本值之和除以样本个数),近似于随机变量的期望(标准概率*样本次数).(样本(部分)趋近于总体)中心极 ...
- Quartz+TopShelf实现Windows服务作业调度
Quartz:首先我贴出来了两段代码(下方),可以看出,首先会根据配置文件(quartz.config),包装出一个Quartz.Core.QuartzScheduler instance,这是一个调 ...
- springboot 使用的配置
1,控制台打印sql logging: level: com.sdyy.test.mapper: debug 2,开启驼峰命名 mybatis.configuration.map-underscore ...
- Session保存数据
int nameid=dao.isLegalUser(name, password);/ /方法返回int数据 request.setAttribute("nam ...
- spring中作用域的问题
在一般情况下:我们登录系统时,第一次登录当用户名或密码输入错误,在登录页面给出错误原因,当我们再刷新登录页面,应该是首次登录系统的页面(这时就不应该再给出出错提示),这时我们就应该想到错误提示信息到底 ...
- JS数组去重办法大全
第一种是比较常规的方法 思路: 1.构建一个新的数组存放结果 2.for循环中每次从原数组中取出一个元素,用这个元素循环与结果数组对比 3.若结果数组中没有该元素,则存到结果数组中 复制代码代码如下: ...
- ubuntu 下当前网速查看
ubuntu下用ethstatus可以监控实时的网卡带宽占用.这个软件能显示当前网卡的 RX 和 TX 速率,单位是Byte 一.安装 ethstatus 软件 #sudo apt-get insta ...
- np.random.randn()、np.random.rand()、np.random.randint()
(1)np.random.randn()函数 语法: np.random.randn(d0,d1,d2……dn) 1)当函数括号内没有参数时,则返回一个浮点数: 2)当函数括号内有一个参数时,则返回秩 ...
- CentOS 安装 Docker CE
准备工作 系统要求 Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10. CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功能(如 overla ...
- [udemy]WebDevelopment_History of The Web
WWW vs Internet For the begining, Internet was there. it was for the academics among universities Th ...