博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU3729--I'm Telling the Truth
阅读量:5327 次
发布时间:2019-06-14

本文共 3741 字,大约阅读时间需要 12 分钟。

I'm Telling the Truth

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 939 Accepted Submission(s): 472
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

 

此题考虑的是最大匹配,然后要按字典序从大到小输出方案。

那匹配的时候就就从num->1,逐个进行匹配,这样能够保证字典序的最大值。

1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 8 #define INF 99999999 9 struct Node 10 { 11 int estart; 12 int eend; 13 }fpoint[100001]; 14 int cx[100001]; 15 int cy[100001]; 16 int mk[100001]; 17 int n; 18 int m; 19 20 void init() 21 { 22 memset(cx,0xff,sizeof(cx)); 23 memset(cy,0xff,sizeof(cy)); 24 memset(mk,0,sizeof(mk)); 25 } 26 27 int path(int u) 28 { 29 int v; 30 for(v=fpoint[u].estart;v<=fpoint[u].eend;v++) 31 { 32 if(!mk[v]) 33 { 34 mk[v]=1; 35 if(cy[v]==-1||path(cy[v])) 36 { 37 cx[u]=v; 38 cy[v]=u; 39 return 1; 40 } 41 } 42 } 43 return 0; 44 } 45 46 int maxmatch() 47 { 48 int i; 49 int sum=0; 50 for(i=m;i>=1;i--) 51 { 52 if(cx[i]==-1) 53 { 54 memset(mk,0,sizeof(mk)); 55 sum+=path(i); 56 } 57 } 58 return sum; 59 } 60 61 int t; 62 63 int main() 64 { 65 scanf("%d",&t); 66 while(t--) 67 { 68 init(); 69 int num; 70 int s,e; 71 scanf("%d",&num); 72 int cnt=1; 73 int mmax=-1; 74 int mmin=INF; 75 m=num; 76 while(num--) 77 { 78 scanf("%d%d",&s,&e); 79 if(mmax
s)mmin=s; 82 if(mmin>e)mmin=e; 83 fpoint[cnt].estart=s; 84 fpoint[cnt++].eend=e; 85 } 86 int ans=maxmatch(); 87 printf("%d\n",ans); 88 int i; 89 cnt=1; 90 for(i=1;i<=m;i++) 91 { 92 if(cx[i]!=-1) 93 { 94 if(cnt
View Code

 

转载于:https://www.cnblogs.com/zafuacm/p/3221106.html

你可能感兴趣的文章
BZOJ 1925: [Sdoi2010]地精部落( dp )
查看>>
c++中的string常用函数用法总结!
查看>>
界面交互之支付宝生活圈pk微信朋友圈
查看>>
[DLX精确覆盖+打表] hdu 2518 Dominoes
查看>>
SuperMap iServerJava 6R扩展领域开发及压力测试---判断点在那个面内(1)
查看>>
Week03-面向对象入门
查看>>
一个控制台程序,模拟机器人对话
查看>>
web.xml 中加载顺序
查看>>
mysql学习之安装(一)
查看>>
[数据库]关于主键与外键
查看>>
pycharm激活地址
查看>>
hdu 1207 四柱汉诺塔
查看>>
Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(上篇——纯前端多页面)
查看>>
display:none与visible:hidden的区别
查看>>
我的PHP学习之路
查看>>
【题解】luogu p2340 奶牛会展
查看>>
wnmp安装配置的坑
查看>>
神奇的Scala Macro之旅(二)- 一个实例
查看>>
sicily 1128. DICE
查看>>
e.Row.Attributes.Add
查看>>