HDu3729最大匹配
来源:互联网 发布:君学书院 知乎 编辑:程序博客网 时间:2024/05/22 08:04
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 Y i (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 Sample Output
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.
245004 50055005 50065004 50065004 500674 52 31 22 24 42 33 4
32 3 451 3 5 6 7
题意: n个人每个人可以在x~y(输入)之间选择一个数(该数被选择后就不能被其他人选择了),问最多有多少个人能选择到数,输出选择最多人的情况中字典树最大的情况。
思路:
每个人对应到x~y之间有联系,形成二部图;求1~100000中与人的最大匹配,由于字典树最大,所以遍历的时候从大到小就可以了。
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#define LL long longtemplate<class T>LL max(T a,T b){return a>b?a:b; } template<class T> LL min(T a, T b) { return a<b?a:b; } const int MAX=105; LL n; bool vism[100005]; LL linked[100005]; struct node { int x,y; }edge[MAX]; bool Dfs(int u) { for(int v=edge[u].x;v<=edge[u].y;v++) { if(!vism[v]) { vism[v]=1; if(linked[v]==-1||Dfs(linked[v])) { linked[v]=u; return 1; } } } return 0; } void Find() { LL hones[MAX]; LL cnt=0; for(int i=n;i>=1;i--) { memset(vism,0,sizeof(vism)); if(Dfs(i)) hones[cnt++]=i; } std::sort(hones,hones+cnt); printf("%lld\n",cnt); for(int i=0;i<cnt;i++) { if(i==0) printf("%lld",hones[i]); else printf(" %lld",hones[i]); } printf("\n"); } int main() { int T; scanf("%d",&T); while(T--) { scanf("%lld",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&edge[i].x,&edge[i].y); //map[b][a]=1; } memset(linked,-1,sizeof(linked)); Find(); } return 0; }
阅读全文
0 0
- HDu3729最大匹配
- hdu3729 I'm Telling the Truth (最大匹配)
- hdu3729 I'm Telling the Truth(二分图最大匹配)
- HDU3729 I'm Telling the Truth(二分图最大匹配)
- hdu3729二分图匹配
- hdu3729—I'm Telling the Truth(二分图最大匹配)
- hdu3729 I'm Telling the Truth【二分图匹配】
- HDU3729 I'm Telling the Truth 匈牙利算法的二分图匹配
- 最大匹配
- 完全匹配-最大匹配
- 二分图+hdu3729
- 【HDU4619】【二分匹配】【最大匹配】
- 正向最大匹配和反向最大匹配
- 最大子串匹配
- 最大正向匹配算法
- 最大字串匹配问题
- 二部图,最大匹配
- [最大匹配]Pku3041--Asteroids
- CUDA从入门到精通(精品)
- Android画画板
- 【GISer小O】JAVA后台的小白之路(一)_1 ——进击吧奔跑的Sumlib Text
- hdu 3501 Calculation 2(欧拉函数+容斥原理)
- 【HNOI2016模拟4.1】神奇的字符串
- HDu3729最大匹配
- ios面试题,各大企业常见的ios面试题之六
- [HDU6070] Dirt Ratio
- 字典序全排列算法
- AC自动机fail指针不基于势能分析构造方法
- 缩放指数型线性单元(SELU)
- Lattice Diamond中VerilogHDL按键延时消抖
- Different Readers for different file types(Tensorflow 的几种读取数据的方式)
- 写在开始