HDU-3729 二分匹配 匈牙利算法
题目大意:学生给出其成绩区间,但可能出现矛盾情况,找出合理组合使没有说谎的人尽可能多,并按maximum lexicographic规则输出组合。
//用学生去和成绩匹配,成绩区间就是学生可以匹配的成绩 #include <iostream>
#include <queue>
#include <vector>
#define N 100005 using namespace std;
struct Node
{
int f,t;
};
Node lis[];
int match[N];
int used[N];
bool dfs(int now)
{
//used[now]=1;
for(int i=lis[now].f;i<=lis[now].t;i++)
{
if(!used[i])
{
used[i]=;
if(match[i]==-||dfs(match[i]))
{
match[i]=now;
return true;
}
}
}
return false;
}
void ini()
{
fill(used,used+N,);
fill(match,match+N,-);
}
int main(int argc, const char * argv[]) {
cin.sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>lis[i].f>>lis[i].t;
int ans=;
ini();
for(int i=n-;i>=;i--)//从n向前遍历,保证尽可能得到大的值
{
fill(used,used+N,);
if(dfs(i))
ans++;
}
cout<<ans<<endl;
priority_queue<int,vector<int>,greater<int> >q;//顺序输出
//int flag=1;
for(int i=N-;i>=;i--)
if(match[i]!=-)
q.push(match[i]+);
while(!q.empty())
{
if(q.size()!=)
cout<<q.top()<<' ';
else
cout<<q.top()<<endl;
q.pop();
}
}
return ;
}
HDU-3729 二分匹配 匈牙利算法的更多相关文章
- 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 ...
- 【I'm Telling the Truth】【HDU - 3729】 【匈牙利算法,DFS】
思路 题意:该题主要说几个同学分别说出自己的名次所处区间,最后输出可能存在的未说谎的人数及对应的学生编号,而且要求字典序最大. 思路:刚刚接触匈牙利算法,了解的还不太清楚,附一个专门讲解匈牙利算法的博 ...
- (二分匹配“匈牙利算法”)无题II --HDU --2236
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2236 代码: #include<cstdio> #include<cstring> ...
- hdu 2063 (二分匹配 匈牙利算法)
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 3729 二分匹配 反向匹配
题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定 点 ...
- 【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 ...
随机推荐
- Linux基础命令---lsusb
lsusb 显示本机的usb设备列表,可以显示出usb的详细信息,包括设备的读取速度和描述符.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE ...
- 小黄人IP营销的四种玩法思维导图
小黄人IP营销的四种玩法思维导图 ------------------------------ 本人微信公众帐号: 心禅道(xinchandao) 本人微信公众帐号:双色球预测合买(ssqyuce)
- vm #set、日期截取、#foreach&#if
<div class="form_row"> <label>状态:</label> #if ($!cp.runState =='t') #set ...
- ArrayList初始化的4种方法
In the last post we discussed about class ArrayList in Javaand it’s important methods. Here we are s ...
- python装饰器,其实就是对闭包的使用。
装饰器 理解装饰器要先理解闭包(在闭包中引用函数,可参考上一篇通过例子来理解闭包). 在代码运行期间动态增加功能的方式,称之为“装饰器”(Decorator). 装饰器的实质就是对闭包的使用,原函数被 ...
- luogu3935 Calculating
标题也许叫整除分块吧 求\(1\)到\(n\)因数的个数\(\sum_{i=1}^n(\sum_{d|n}1)\) 范围\(1e14\)时限3s \(n\sqrt{n}\)的暴力铁定gg 分开考虑 \ ...
- POJ3241 Object Clustering(最小生成树)题解
题意:求最小生成树第K大的边权值 思路: 如果暴力加边再用Kruskal,边太多会超时.这里用一个算法来减少有效边的加入. 边权值为点间曼哈顿距离,那么每个点的有效加边选择应该是和他最近的4个象限方向 ...
- Java propertis文件中组装配置
目的: 实现在配置文件中,进行组装 1.Properties文件配置如下: dns=http://211.103.227.133:8080 qrcode=${dns}/wx/views/invite/ ...
- RMQ 区间最大值 最小值查询
/*RMQ 更新最小值操作 By:draymonder*/ #include <iostream> #include <cstdio> using namespace std; ...
- BZOJ1355: [Baltic2009]Radio Transmission KMP
Description 给你一个字符串,它是由某个字符串不断自我连接形成的. 但是这个字符串是不确定的,现在只想知道它的最短长度是多少. Input 第一行给出字符串的长度,1 < L ≤ 1, ...