hdu 3729 I'm Telling the Truth(最大匹配)
来源:互联网 发布:网络暴力的危害 编辑:程序博客网 时间:2024/06/05 00:07
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.
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题意:有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(二分图最大匹配,字典序最大输出)
- 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 -- 二分图最大匹配 输出方案
- 二分图的最大匹配-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
- HDU 3729 I'm Telling the Truth
- HDU 3729I'm Telling the Truth
- 在 actionbarsherlock 上如何对 item 使用自定义的 view
- HDU 2389
- javascript各种倒计时
- 二叉排序树之删除节点
- VS2010安装/瘦身/精简/提速方法
- hdu 3729 I'm Telling the Truth(最大匹配)
- JAVA学习二十:IO流
- 剑指Offer算法实现之八:旋转数组的最小数字
- JAVA学习二十一:GUI图形用户界面
- UVA 10050 Hartals
- [leetcode] Longest Valid Parentheses
- 程序员,你当的了吗?——读《高效能程序员的修炼》有感
- HTTP 错误 500.21 - Internal Server Error 处理程序“PageHandlerFactory-ISAPI-4.0_32bit”在其模块
- 《iOS应用程序开发方法与实践》补充内容-2.13 再谈类的声明与实现