hdu 3729 I'm Telling the Truth(最大匹配)
2013-08-02 21:10
423 查看
I'm Telling the Truth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 982 Accepted Submission(s): 491
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 题意:有n个学生,每个学生给出他的成绩所在的区间。输出最多有多少个学生说真话,并且按字典序输出说真话的学生编号,若有多种情况,则输出字典序最大的。思路:二分图的最大匹配。将学生与成绩进行匹配。由于要求输出字典序最大的序列,我们可以从学生n开始匹配,这样就会使学生编号大的先匹配。 AC代码:#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <queue> #include <vector> #include <cmath> #include <stack> #include <cstdlib> using namespace std; const int INF=1000000000; const int maxn=100005; struct node { int x,y; }score[65]; int match1[maxn],match2[maxn]; bool vis[maxn]; int n; bool find(int x) { for(int i=score[x].x;i<=score[x].y;i++) if(!vis[i]) { vis[i]=true; if(match1[i]==-1||find(match1[i])) { match1[i]=x; match2[x]=i; return true; } } return false; } int MMG() { int ans=0; memset(match1,-1,sizeof(match1)); memset(match2,-1,sizeof(match2)); for(int i=n;i>=1;i--) { memset(vis,false,sizeof(vis)); if(find(i)) ans++; } return ans; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&score[i].x,&score[i].y); int sum=MMG(); printf("%d\n",sum); for(int i=1;i<=n;i++) { if(match2[i]!=-1) { if(sum>1) printf("%d ",i); else printf("%d\n",i); --sum; } } } return 0; }
相关文章推荐
- HDU 3729 I'm Telling the Truth(二分图最大匹配)
- HDU 3729-I'm Telling the Truth-周赛4补题-二分图最大匹配-邻接表
- HDU 3729 I'm Telling the Truth(二分图最大匹配)
- hdu 3729 I'm Telling the Truth(二分图最大匹配)
- HDU 3729 I'm Telling the Truth -- 二分图最大匹配 输出方案
- 二分图的最大匹配-hdu-3729-I'm Telling the Truth
- HDU 3729 I'm Telling the Truth(二部图最大匹配+结果输出)
- 二分图的最大匹配-hdu-3729-I'm Telling the Truth
- HDU I'm Telling the Truth (二分图最大匹配+字典序最大路径输出(好题))
- 【HDU】3729 I'm Telling the Truth 离散+最大流
- 【HDOJ 3729】 I'm Telling the Truth (二分图最大匹配)
- hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)
- HDOJ 3729 - I'm Telling the Truth 水二分图最大匹配
- hdu 3729 I'm Telling the Truth 二分图匹配
- HDU 3729 I'm Telling the Truth(二分图最大匹配)
- HDU 3729 I'm Telling the Truth(二分图最大匹配+结果输出)
- hdu 3729 I'm Telling the Truth
- HDU - 3729 I'm Telling the Truth 二分图最大匹配 匈牙利算法
- hdu 3729 I'm Telling the Truth(二分图最大匹配,字典序最大输出)
- HDU 3729 — I'm Telling the Truth