题目大意:学生给出其成绩区间,但可能出现矛盾情况,找出合理组合使没有说谎的人尽可能多,并按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 二分匹配 匈牙利算法的更多相关文章

  1. hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  2. 【01染色法判断二分匹配+匈牙利算法求最大匹配】HDU The Accomodation of Students

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 [DFS染色] #include<iostream> #include<cstdio&g ...

  3. 【I'm Telling the Truth】【HDU - 3729】 【匈牙利算法,DFS】

    思路 题意:该题主要说几个同学分别说出自己的名次所处区间,最后输出可能存在的未说谎的人数及对应的学生编号,而且要求字典序最大. 思路:刚刚接触匈牙利算法,了解的还不太清楚,附一个专门讲解匈牙利算法的博 ...

  4. (二分匹配“匈牙利算法”)无题II --HDU --2236

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2236 代码: #include<cstdio> #include<cstring> ...

  5. hdu 2063 (二分匹配 匈牙利算法)

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. HDU 3729 二分匹配 反向匹配

    题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定  点 ...

  7. 【HDU 2255】奔小康赚大钱 (最佳二分匹配KM算法)

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  8. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)

    The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...

随机推荐

  1. git仓库按时间、成员等维度分析统计

    git 按时间打印所有成员代码提交: git log --since ==2018-01-01 --until=2018-12-31 --format='%aN' | sort -u | while ...

  2. php ci 报错 Object not found! The requested URL was not found on this server. If you entered the URL manually please check

    Object not found! The requested URL was not found on this server. The link on the referring page see ...

  3. ui-grid angularjs

    <pre name="code" class="html"><!--ui-grid css--> <link rel=" ...

  4. Python入门之logging模块

    本章目录: 一.logging模块简介 二.logging模块的使用 三.通过JSON或者YMAL文件配置logging模块 ===================================== ...

  5. Kafka学习之(七)搭建kafka可视化服务Kafka Eagle

    一.下载安装包  kafka-eagle-bin-1.2.4.tar.gz 百度云链接:链接:https://pan.baidu.com/s/1SNIkpsvs20A_Ljtx5PaMuA 密码:o4 ...

  6. P4180 【模板】严格次小生成树[BJWC2010]

    P4180 [模板]严格次小生成树[BJWC2010] 倍增(LCA)+最小生成树 施工队挖断学校光缆导致断网1天(大雾) 考虑直接枚举不在最小生成树上的边.但是边权可能与最小生成树上的边相等,这样删 ...

  7. python3 清除过滤emoji表情

    python3 清除过滤emoji表情 方法一: emoji处理库,emoji官网:https://pypi.org/project/emoji/ #安装 pip install emoji 官方例子 ...

  8. 在wamp 2.0环境下面安装Zend Optimizer的方法

    原文链接:http://blog.sina.com.cn/s/blog_8dc13ec50101pbat.html 我是用WAMP来做PHP的服务器,进行本机测试和开发PHP项目. wamp环境是刚刚 ...

  9. Python3基础 os listdir 列举指定的所有文件及文件夹的名字

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. 利用Qt开发跨平台APP

    本文将手把手教你如何在Windows环境下,使用Qt编译出安卓应用程序. Qt是一个优秀的跨平台开发工具.我们利用Qt可以很方便地将一次编写的应用,多次编译到不同平台上,如Windows.Linux. ...