I'm telling the truth
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1335 accepted submission (s): 686
Problem descriptionafter 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, when said he was between 5004th and 5005th, then said he was between 5005th and 5006th, then said he was between 5004th and 5006th, then said he was between 5004th and second, too. this situation is obviusly 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.
Inputthere 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.
Outputoutput 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#include<stdio.h>#include<iostream>#include<string.h>using namespace std;#define N 100005int x[65],y[65],vist[N],match[N],n;int find(int i){ for(int j=x[i];j<=y[i];j++) if(vist[j]==0) { vist[j]=1; if(match[j]==0||find(match[j])) { match[j]=i; return 1; } } return 0;}int main(){ int t,ans,s[65]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]); memset(match,0,sizeof(match)); ans=0; for(int i=n;i>0;i--) { memset(vist,0,sizeof(vist)); if(find(i)) s[ans++]=i; } printf("%d\n",ans); if(ans)printf("%d",s[ans-1]); for(int i=ans-2;i>=0;i--) printf(" %d",s[i]); printf("\n"); }}