HDU 3729 I'm Telling the Truth

来源:互联网 发布:炫光软件 编辑:程序博客网 时间:2024/05/16 02:00

题目链接 : HDU3729

I'm Telling the Truth

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


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
245004 50055005 50065004 50065004 500674 52 31 22 24 42 33 4
 


 

Sample Output
32 3 451 3 5 6 7
 


 

Source
2010 Asia Tianjin Regional Contest
 


 

Recommend
zhouzeyong
 
 
经典的二分图模型
 
 
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#include<string>#include<vector>#include<map>#include<list>using namespace std;int gra[65][2],n;bool vis[100005];int p[100005],o[65];bool find(int s){    for(int i=gra[s][0];i<=gra[s][1];i++)        if(vis[i]==0)        {            vis[i]=1;            if(p[i]==0 || find(p[i]))            {                p[i]=s;                return 1;            }        }    return 0;}int max_match(){    int ans=0;    memset(p,0,sizeof(p));    for(int i=n;i>0;i--)    {        memset(vis,0,sizeof(vis));        if(find(i)) o[ans++]=i;    }    return ans;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        int x,y;        scanf("%d",&n);        for(int i=1;i<=n;i++)            scanf("%d%d",&gra[i][0],&gra[i][1]);        int temp;        printf("%d\n",temp=max_match());        for(int i=temp-1;i>0;i--)            printf("%d ",o[i]);        printf("%d\n",o[0]);    }    return 0;}

 

原创粉丝点击