(二分匹配“匈牙利算法”)无题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 ...
随机推荐
- sqlserver分布式 用触发器插入数据
这个月总公司收购了一家小公司,这家小公司的数据库用的是32位的 Sql2000 ,已经使用很长一段时间了,系统也比较稳定.本着节约成本的原则,总公司保留原公司的一套管理系统,但要求重要数据每天上传到总 ...
- sql server 2000能否得到一个表的最后更新日期?
如果是SQL 2005 或 2008.运行下面的代码.就可以看到从上次启动SQL 服务以来,某个表的使用情况,包括select/update/delete/insert. SELECT * FROM ...
- Jquery detect page refresh
first thing there are 3 functions we will use: function setCookie(c_name, value, exdays) { ...
- 协同过滤 spark scala
1 http://www.cnblogs.com/charlesblc/p/6165201.html [转载]协同过滤 & Spark机器学习实战 2 基于Spark构建推荐引擎之一:基于物品 ...
- PCA和SVD(转)
最近突然看到一个问题,PCA和SVD有什么关系?隐约记得自己照猫画虎实现的时候PCA的时候明明用到了SVD啊,但SVD(奇异值分解)和PCA的(特征值分解)貌似差得相当远,由此钻下去搜集了一些资料,把 ...
- mysql异常
一.Can't connect to MySQL server on 'localhost' (10061)翻译:不能连接到 localhost 上的mysql分析:这说明“localhost”计算机 ...
- Spring AOP开发
--------------------siwuxie095 Spring AOP 开发 1.在 Spring 中进行 ...
- UVa 10763 Foreign Exchange(map)
Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...
- 18-javaweb-ssm 开发中错误总结
由于web课设于是,写了几天的javaweb,在写的过程中总会遇到奇奇怪怪的一些bug, 一般都得花很多时间解决. 但是解决多了,后面碰到类似的简单多了. 总结下: 一.前端错误: 1.js错误,看前 ...
- jdeveloper基础教程(中文版)
jdeveloper基础教程(中文版) 程序员的基础教程:菜鸟程序员