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. Git安装配置(完整版)

    首先安装Windows客户端的git和TortoiseGit. 安装这两个软件还是蛮重要的,很多选项不能乱选. 为了写个完整的博客,我是装了又卸,卸了又装. 1.安装git 下载:https://gi ...

  2. Linux下检测进程是否存在

    这个问题看起来好像很简单,"ps -ef | grep xx"一下就行啦!这样做当然可以,但是如果我们考究起性能来,这恐怕不是个好办法. 假设我们现在要监测某进程是否存活,每分钟检 ...

  3. myeclipse eclipse创建maven web项目时 index.jsp报错

    第一种办法 解决办法: ---------------------------------------------------------------------------------------- ...

  4. sed修炼系列(四):sed中的疑难杂症

    本文目录:1 sed中使用变量和变量替换的问题2 反向引用失效问题3 "-i"选项的文件保存问题4 贪婪匹配问题5 sed命令"a"和"N" ...

  5. 使用Sidecar将Node.js引入Spring Cloud

    网上看到的一篇文章,觉得写得挺好,现转载于此,以方便需要的网友查阅. 该文章介绍了非JAVA语言提供的应用集成到Spring Cloud的这样一个实现,以便我们使用其他语言作为参考. 感谢原作者分享, ...

  6. 深入理解计算机系统(2.3)------布尔代数以及C语言运算符

    本篇博客我们主要讲解计算机中的布尔代数以及C语言的几个运算符. 1.布尔代数 我们知道二进制值是计算机编码.存储和操作信息的核心,随着计算机的发展,围绕数值0和1的研究已经演化出了丰富的数学知识体系. ...

  7. RAID RAID 大揭秘~

    p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; text-align: justify; f ...

  8. 游戏平台代表--PS4【推荐】

    目前市上专业的游戏主机三足鼎立,分别是任天堂的wii,微软的xbox,已经索尼的PlayStation系列,这其中的老大当然是索尼PS4啦,因为即使美国佬也是优选ps4而不是自家的Xbox.小编历经千 ...

  9. 联想G50-70安装SSD及WIN10教程

    借着双11的东风,果断入手SSD120G和4G内存条1枚.经过近一周的安装与试运行,笔者实现了SSD+HDD双硬盘+WIN10系统.目前运行体验非常好,开机时间9秒,软件运行也非常流畅.在折腾的过程中 ...

  10. 201521123008《Java程序设计》第1周学习总结

    本周学习总结 了解了JAVA:jdk:jre:jvm等 C语音与JAVA的部分区别: C语言全面向过程,java面向对象: C语言的代码不能跨平台,java的代码可以跨平台: C语言有指针,java没 ...