I'm Telling the Truth

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1033    Accepted Submission(s): 510

Problem Description
After this year’s college-entrance exam, the teacher did a survey in his class on students’ score. There are n students in the class. The students didn’t want to tell their
teacher their exact score; they only told their teacher their rank in the province (in the form of intervals).
After asking all the students, the teacher found that some students didn’t tell the truth. For example, Student1 said he was between 5004th and 5005th, Student2 said he
was between 5005th and 5006th, Student3 said he was between 5004th and 5006th, Student4 said he was between 5004th and 5006th, too. This situation is obviously
impossible. So at least one told a lie. Because the teacher thinks most of his students are honest, he wants to know how many students told the truth at most.
 
 
Input
There is an integer in the first line, represents the number of cases (at most 100 cases). In the first line of every case, an integer n (n <= 60) represents the number
of students. In the next n lines of every case, there are 2 numbers in each line, Xi and Yi (1 <= Xi <= Yi <= 100000), means the i-th student’s rank is between Xi and Yi, inclusive.
 
Output
Output 2 lines for every case. Output a single number in the first line, which means the number of students who told the truth at most. In the second line, output the
students who tell the truth, separated by a space. Please note that there are no spaces at the head or tail of each line. If there are more than one way, output the list with
maximum lexicographic. (In the example above, 1 2 3;1 2 4;1 3 4;2 3 4 are all OK, and 2 3 4 with maximum lexicographic)
 
Sample Input
2
4
5004 5005
5005 5006
5004 5006
5004 5006
7
4 5
2 3
1 2
2 2
4 4
2 3
3 4
 
Sample Output
3
2 3 4
5
1 3 5 6 7

一个水的二分匹配题,我用的是DFS找增广路算法:

 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
typedef struct abcd
{
int x,y;
}abcd;
abcd a[];
int b[];
int c[];
set<int> s;
int dfs(int t)
{
int i;
for(i=a[t].x;i<=a[t].y;i++)
{
if(!c[i])
{
c[i]=;
if(!b[i]||dfs(b[i]))
{
b[i]=t;
s.insert(t);
return ;
}
}
}
return ;
}
int main()
{
int n,m,i,j;
cin>>n;
for(i=;i<n;i++)
{
s.clear();
memset(b,,sizeof(b));
cin>>m;
for(j=;j<=m;j++)
{
cin>>a[j].x>>a[j].y;
}
int sum=;
for(j=m;j>;j--)
{
memset(c,,sizeof(c));
if(dfs(j))
sum++;
}
cout<<sum<<endl;
set<int> ::iterator it;
for(it=s.begin();it!=s.end();it++)
{
sum--;
if(sum)
cout<<(*it)<<' ';
else cout<<(*it)<<endl;
}
}
}

hdu3729二分匹配的更多相关文章

  1. HDU-3729 二分匹配 匈牙利算法

    题目大意:学生给出其成绩区间,但可能出现矛盾情况,找出合理组合使没有说谎的人尽可能多,并按maximum lexicographic规则输出组合. //用学生去和成绩匹配,成绩区间就是学生可以匹配的成 ...

  2. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  3. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  4. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  5. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  6. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  7. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  8. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  9. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

随机推荐

  1. Vue相关(过渡动画)

    Vue 过渡 && 动画 一.CSS过渡 1.transition标签可以用来封装需要过渡的元素,添加entering/leaving 过渡, 条件是: (1)使用条件渲染语句 v-i ...

  2. photoshop软件应用手记

    ------------------------常用图片格式------------------------ 位图和矢量图 位图也叫点阵图,是由一个个的方形的像素点排列在一起拼接而成的,位图在放大时, ...

  3. java内存区域分析及java对象的创建

    java虚拟机在执行java程序的过程中会将它管理的内存区域加分为若干个的不同的数据区域. 主要包括以下几个运行时数据区域,这里就只介绍经常会用到的 1:java虚拟机栈:我们常说的堆栈,栈就是指的j ...

  4. Windows noinstall zip 安装MySQL。

    听完数据库老师的课,想在Windows下通过命令行的方法安装MySQL5.7,于是开了这个坑,终于把这个坑填上了. 第一步:下载MySQL 的noinstall zip ,点击该链接下载,或者复制链接 ...

  5. select设置disable后ie修改默认字体颜色暂时解决

    找了很多资料,终于在科学上网后找到了一个方法,虽然暂时不知道原理,但是已经实现了功能就是好的 select[disabled='disabled']::-ms-value { color: #000; ...

  6. 结对编程1——四则运算-GUI

    码市链接:https://coding.net/u/hmhhh/p/hmh-homework/git/tree/master/ 201421123003 黄建英 201421123004 黄美海 题目 ...

  7. java中null的类型匹配

    null作为一个特殊的参数匹配为String对象

  8. 团队作业8----第二次项目冲刺(beta阶段)5.23

    Day5-05.23 1.每日会议 会议内容: 1.组长林乔桦对昨日的工作进行了总结并且安排今日的任务. 2.潘益靖副组长说明昨日任务的完成情况. 3.组员对昨天的各项工作进行了汇报以及对今天的工作进 ...

  9. 201521123079《Java程序设计》第2周学习总结

    1. 本周学习总结 学会String类和StringBuilder类的一些用法. 学会使用码云管理代码,会将码云上的代码和本地仓库关联 2. 书面作业 Q1.使用Eclipse关联jdk源代码,并查看 ...

  10. 201521123033《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. answer: 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号 ...