、I’m Telling the Truth

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1740 Accepted Submission(s): 871

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

Source

2010 Asia Tianjin Regional Contest

二分图模板题

#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define PI cos(-1.0)
#define RR freopen("input.txt","r",stdin)
using namespace std;
const int Max= 100010;
bool Mark[Max];
int pre[Max];
struct node
{
int L;
int R;
}a[65];
int b[65];
int vis[65];
int num,n;
bool DFS(int s)
{
for(int i=a[s].L;i<=a[s].R;i++)
{
if(!Mark[i])
{
Mark[i]=true;
if(pre[i]==-1||DFS(pre[i]))
{
pre[i]=s;
return 1;
}
}
}
return 0;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d %d",&a[i].L,&a[i].R);
}
num=0;
memset(pre,-1,sizeof(pre));
for(int i=n;i>=1;i--)
{
memset(Mark,false,sizeof(Mark));
if(DFS(i))
{
b[num++]=i;
}
}
printf("%d\n",num);
for(int i=num-1;i>=0;i--)
{
if(i!=num-1)
{
printf(" ");
}
printf("%d",b[i]);
}
printf("\n");
}
return 0;
}

I'm Telling the Truth(二分图)的更多相关文章

  1. UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)

    I - I'm Telling the Truth Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  2. hdu 3729 I'm Telling the Truth 二分图匹配

    裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...

  3. hdu3729 I'm Telling the Truth (二分图的最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS (Java/ ...

  4. hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS ( ...

  5. 二分图的最大匹配-hdu-3729-I'm Telling the Truth

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3729 题目意思: 有n个学生,老师询问每个学生的排名,每个学生都告诉了一个排名区间,求可能的最多的学 ...

  6. HDU3729 I'm Telling the Truth(字典序最大的最大流)

    题目大概说n个学生,都各自有一个互不相同的成绩排名,他们各自说了他们成绩排名所在区间,问最多有几个学生没说谎以及字典序最大的没说谎的学生序列. 学生作为一个X部的点,排名作为Y部的点,学生与其成绩排名 ...

  7. HDU 3729 I&#39;m Telling the Truth(二部图最大匹配+结果输出)

    职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...

  8. HDU-3729 I'm Telling the Truth

    一个点集是学生,一个点集是排名.然后通过学生的排名范围连线,求此二分图的最大匹配. 本题还要求是最大字典序输出,那么由贪心可得,你让标号从大到小找增广边就行了. #include <cstdli ...

  9. HDU 3729 I'm Telling the Truth (二分匹配)

    题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...

随机推荐

  1. LaTeX 有哪些「新手须知」的内容?

    孟晨 ,在 LaTeX 话题下写错 LaTeX 名字的,一律… 陈硕等 137 人赞同 这是个好问题,虽然提问提得很大.不是很好答,权当抛砖引玉了. 天字第一号原则:不要到网上抄代码,尤其是似懂非懂的 ...

  2. Leetcode: Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  3. JS练习 改变文本框状态

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Python学习总结3:元组、列表的操作汇总

    参考博客:http://www.cnblogs.com/QG-whz/p/4782809.html 1. 是否可变 元组:用()或tuple函数定义,不可变(元素的值以及整个元组): 列表:用 [] ...

  5. JS_01_入门学习

    01:编写js文件:JavaScript_01.js // JavaScript Document //1.利用JavaScript来输出文字 <script type="text/j ...

  6. 关于设置oracle中系统编号SYSID自动编号的问题;

    http://liye9801.blog.163.com/blog/static/601970320086210039591/ 如何在oracle里设置自动编号列 2008-07-21 12:00:3 ...

  7. react绑定事件

    1.显示隐藏 2.输入框输入内容,立即显示出来 代码如下: 注意:版本 React v15.0.1 ReactDOM v15.0.1 browser.min.js是编译文件,将代码解析为浏览器识别的j ...

  8. 夺命雷公狗TP下关联查询

    记录下我们常用的关联查询: public function add4(){ $id=$_GET['id']; $this->list = M("student")->t ...

  9. Hadoop之TaskAttemptContext类和TaskAttemptID类

    先来看看TaskAttemptContext的类图 : Figure1:TaskAttemptContext类图 用户向Hadoop提交Job(作业),Job在JobTracker对象的控制下执行.J ...

  10. ASP.NET输出流至少要有256个字节的数据后Response.Flush方法才会生效

    很多时候我们写的asp.net程序会因为做很多操作,所以会花上一分钟甚至几分钟时间.为了使软件使用者能够耐心的等待程序的执行,我们经常会希望有一个进度条来表示程序执行的状态.或者最起码要显示一个类似: ...