I'm Telling the Truth
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 340Accepted Submission(s): 162
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
Source
非常基本的最大匹配。
只不过要输出方案。
建图很容易,可以直接从每一个人连接到每一个排名
然后最大匹配,完事后,因为要输出最大的字典序
所以,在匹配的时候我们倒过来匹配,从最大的n匹配到1
这样存好答案之后在排个序,输出来就OK了
另外:
由于这个题的那段区间非常大。但是人却非常少。所以有一个节约内存和时间的方法
我们可以用vector来存图,然后用map来标记
这样节约时间和空间。
详细见代码:
分享到:
相关推荐
杭电ACM课件2014版之(HDUACM2010版_13)二分匹配及其应用
杭电hdu acm资料所用杭电的acm题
(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
此程序为hdu的acm2010题,就是解决水仙花数问题
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
HDUACM2010版13二分匹配及其应用.ppt
杭电 hdu acm 第1084题的解法,ac过了,是一位学长教我的.内有一些中文说明.
ACM/ICPC 2010年多校联合第十场第九题的解题报告及代码,AC代码有三个,最好的是src
ACM HDU题目分类,我自己总结的大概只有十来个吧
自己做的HDU ACM已经AC的题目
HDU图论题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用
HDU_ACM培训课件(完整版) HDU_ACM培训课件(完整版) HDU_ACM培训课件(完整版) HDU_ACM培训课件(完整版)
杭电acm解题报告 详细解析2000-2099 适合acm初学者
HDU的ACM,非常的好 涉及了很多算法,例如二分匹配、博弈、组合、最小生成树、搜索、动态规划、贪心算法
经典算法:(二分匹配,背包专题,筛选法,简单数学题,贪心算法,递推求解,动态规划,并查集,母函数,搜索,组合博弈等入门算法)
acm 技术大牛 课件 HDU 自学必备课件 全套齐全 (lecture_01)初识ACM (lecture_02)简单数学题 (lecture_03)递推求解 (lecture_04)动态规划(1)_ (lecture_05)计算几何基础_ (lecture_06)母函数 (lecture_...