、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. 查询功能:yum [list|info|search|provides|whatprovides] 参数

    [root@www ~]# yum [option] [查询工作项目] [相关参数] 选项与参数: [option]:主要的选项,包括有:   -y :当 yum 要等待使用者输入时,这个选项可以自动 ...

  2. 我写了本破书-swift语言实战晋级

    本书是一本介绍Swift实战的实用图书,旨在帮有一定编程基础的童鞋能够快速上手Swift. 本书的结构是先讲解了Swift语言的精要,没有基础的童鞋可以学习,有基础的童鞋可以当做复习. 接着讲解如何用 ...

  3. 【Origin】 偶题 之 抒意

    作词抒胸臆, 辞赋九万里: 从南盖到北, 句句表挚期. -作于二零一五年七月十五日

  4. csuoj 1111: 三家人

    acm.csu.edu.cn/OnlineJudge/problem.php?id=1111 1111: 三家人 Time Limit: 1 Sec  Memory Limit: 128 MBSubm ...

  5. [原创]java WEB学习笔记84:Hibernate学习之路-- -映射 一对一关系 ,基外键的方式实现

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  6. [转]easyui data-options的使用

    原文地址:easyui data-options的使用 data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我们可以对easyui组件的实例化可以完全 ...

  7. SQL 存储和触发器

    存储过程:就像函数一样的会保存在数据库中-->可编程性 --> 存储过程 创建存储过程:create proc JiaFa--需要的参数@a int,@b intas --存储过程的内容 ...

  8. java程序运行时内存分配详解 (转)

    转自:http://www.tuicool.com/articles/uU77v2 一.  基本概念 每运行一个java程序会产生一个java进程,每个java进程可能包含一个或者多个线程,每一个Ja ...

  9. JSP里比对单选框或复选框的数值而自动打勾

    <table> <tr> <td class="tableleft">状态</td> <td><input typ ...

  10. 直关的sql 联级更新语句

    在sql-server中用这种写法最直观:UPDATE a SET a.c = b.c FROM table1 ainner join table2 b on b.a=a.aWHERE a.c is ...