(二分匹配“匈牙利算法”)无题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 ...
随机推荐
- git 使用 添加分支
http://jingyan.baidu.com/album/19192ad83ea879e53e5707ce.html?picindex=1 修改配置 git config --global use ...
- chnagyong sql
select gid,count(distinct mid) from members group by gid mysql> SELECT IFNULL(NULL,); mysql> 1 ...
- rabbitmq web管理界面 用户管理
安装最新版本的rabbitmq(3.3.1),并启用management plugin后,使用默认的账号guest登陆管理控制台,却提示登陆失败. 翻看官方的release文档后,得知由于账号gues ...
- C++中的浅拷贝和深拷贝
浅拷贝(shallow copy)与深拷贝(deep copy)对于值拷贝的处理相同,都是创建新对象,但对于引用拷贝的处理不同,深拷贝将会重新创建新对象,返回新对象的引用字.浅拷贝不会创建新引用类型. ...
- C & C++ 宏与const
1.宏定义函数: 例:#define do{exp} while(0)与#define exp有什么不同,好处在哪里? 定义复杂代码,防止分号,或是括号不匹配等错误.比如: 定义: #define s ...
- Median(二分+二分)
Median http://poj.org/problem?id=3579 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- DOS批处理前言
-----------made by siwuxie095 1.批处理(Batch):望文知义,对某对象进行批量处理,实际上是一种脚本 2.DOS(Disk Operating System-磁盘操作 ...
- 使用ASP.NET AJAX 从脚本中调用Web 服务的应用方法
技能点:通过编写WebService,在页面js中调用WebService来进行数据查询. 网站开发,有些时候需要使用js在页面动态生成一些内容,但还有些数据要通过查询数据库才能获取的. 但由于诸如主 ...
- 14- Servlet.service() for servlet [mvc-dispatcher] in context with path [/collegeservice] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root caus
有的service没有依赖注入:
- 子类覆写的变量被private隐藏,强制转换方式通过子类访问父类的被覆写变量:
import static java.lang.System.*; public class SuperParent{ public static void main(String[] args){ ...