题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721

来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26644#problem/F

Final Exam Arrangement


Time Limit: 4 Seconds      Memory Limit: 65536 KB      Special Judge


In Zhejiang University, there are N different courses labeled from 1 to N. Each course has its own time slot during the week. We can represent the time
slot of a course by an left-closed right-open interval [s, t).

Now we are going to arrange the final exam time of all the courses.

The final exam period will contain multiple days. In each day, multiple final exams will be held simultaneously. If two courses' time slots are not overlapped, there may be students who
are attending both of them, so we cannot arrange their final exams at the same day.

Now you're to arrange the final exam period, to make the total days as small as possible.

Input

There are multiple test cases separated by blank lines.

For each ease, the 1st line contains one integer N(1<=N<=100000).

Then N lines, the i+1th line contains s and t of the interval [s, t) for the ith course.(0<=s<t<=231-1)

There is a blank line after each test case.

Output

For each case, the 1st line contains the days P in the shortest final exam period.

Next P lines, the i+1th line contains the numbers of courses whose final exam is arranged on the ith day separated by one space.

Output a blank line after each test case.

Sample Input

  1. 4
  2. 0 1
  3. 1 2
  4. 2 3
  5. 3 4
  6.  
  7. 4
  8. 0 2
  9. 1 3
  10. 2 4
  11. 3 5
  12.  
  13. 4
  14. 0 4
  15. 1 5
  16. 2 4
  17. 3 6

Sample Output

  1. 4
  2. 1
  3. 2
  4. 3
  5. 4
  6.  
  7. 2
  8. 1 2
  9. 3 4
  10.  
  11. 1
  12. 1 2 3 4

题意:感觉很奇怪,为什么重合的可以放在同一天考试,虽然AC了,但是还是没有看懂
  题目意思,比赛时按照题目要求弄了下,两个排序一下就过了。(其实一个就够
  了)

思路:先按照开始的时间和结束的时间从前往后排序。

当然是先开始的 排在前面,同时开始的,先结束的排在前面了

排序好后的第一门课当然是在第一天考试了。

然后依次遍历后面的每一门课,如果后面一门课和前面的有相交的区间,则它们在同一天考试,此时要注意缩小这天的可以考试的区间,后开始早结束,取相交的部分。如果没有相交的部分,那么区间还是自己的开始和结束时间,只是考试时间推后了一天。

最后是输出,我是按照考试时间排序了下,再调整了下输出格式。

F Accepted 1744 KB 1210 ms C++ (g++ 4.4.5) 1206 B 2013-07-20 12:19:25

  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<string.h>
  4. using namespace std;
  5.  
  6. const int maxn = 100000+10;
  7. struct Class{
  8. int s,t;
  9. int flag;
  10. int index;
  11. }c[maxn];
  12.  
  13. bool cmp(Class a, Class b)
  14. {
  15. if(a.s != b.s) return a.s < b.s;
  16. else return a.t < b.t;
  17. }
  18.  
  19. bool cmp1(Class a, Class b)
  20. {
  21. if(a.flag == b.flag) return a.index <= b.index;
  22.  
  23. else return a.flag < b.flag;
  24. }
  25.  
  26. int main()
  27. {
  28. int n;
  29. while(scanf("%d", &n) != EOF)
  30. {
  31. for(int i = 0; i < n; i++)
  32. {
  33. scanf("%d%d", &c[i].s, &c[i].t);
  34. c[i].flag = 0;
  35. c[i].index = i+1;
  36. }
  37. sort(c,c+n,cmp);
  38. c[0].flag=1;
  39. for(int i = 1; i < n; i++)
  40. {
  41. if(c[i].s < c[i-1].t)
  42. {
  43. c[i].flag = c[i-1].flag;
  44. c[i].s = max(c[i].s, c[i-1].s);
  45. c[i].t = min(c[i].t, c[i-1].t);
  46. }
  47. else c[i].flag = c[i-1].flag+1;
  48. }
  49. int day = c[n-1].flag;
  50.  
  51. int d = 1;
  52. sort(c,c+n,cmp1);
  53. printf("%d\n",day);
  54.  
  55. int f = 1;
  56.  
  57. for(int i = 0; i < n; i++)
  58. {
  59.  
  60. if(c[i].flag == d ) {
  61. if(f == 1) { f = 2; printf("%d", c[i].index); }
  62. else {
  63. printf(" %d", c[i].index);
  64. }
  65. }
  66.  
  67. else{
  68. printf("\n");
  69. d += 1;
  70.  
  71. printf("%d", c[i].index);
  72. }
  73. }
  74. printf("\n");
  75. }
  76. return 0;
  77. }

zoj 3721 Final Exam Arrangement【贪心】的更多相关文章

  1. ZOJ-3721 Final Exam Arrangement 贪心

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3721 容易的贪心题,排个序.. //STATUS:C++_AC_ ...

  2. Final Exam Arrangement(ZOJ)

    In Zhejiang University, there are N different courses labeled from 1 to N. Each course has its own t ...

  3. [CF] Final Exam Arrangement

    问题链接:http://www.bnuoj.com/v3/contest_show.php?cid=4329#problem/F   问题大意:         就是有1--N们课程,每一个课程都有一 ...

  4. 【HDOJ6651】Final Exam(贪心)

    题意:有n门课,价值之和为m,每门课的价值可能是0到m 一门价值为x的课需要花至少x+1时间准备才能通过 问不管价值如何分配都能通过至少k门课的最小总准备时间 m,n,k<=1e9 思路: #i ...

  5. HDU 6651 Final Exam (思维)

    2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...

  6. 2019 Multi-University Training Contest 7 Kejin Player Final Exam

    Kejin Player 期望DP 题意: 初始等级为1,每一级有四个参数 r , s , x , a . 每一级有一个概率p=r/s花费a的代价升级到下一级,失败可能会倒退到x级 设从 l 到 r ...

  7. 2019HDU多校第七场 HDU6651 Final Exam

    一.题目 Final Exam 二.分析 题目说的比较绕,总之一定要记住,$n$个题目都可以做,至少作对$k$到,但是做题目的人不知道每道题对应的分数. 作为出题人,如果他是田忌,肯定不会去在做题目的 ...

  8. Exam(贪心)

    Exam Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. hdu 5240 Exam(贪心)

    Exam Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. 计算机速度GHz等于每秒多少次

    这个是没有对比关系的.需要看处理器的微指令.计算机的GHz指的是CPU的时钟频率,不同的指令需要的时钟个数是不同的,列如,从内存读一个数据,一般需要4个时钟周期,而进行一次8位数的加法运算,一般需要1 ...

  2. Windows 10 Enterprise LTSB版本

    Windows 10 Enterprise 评估版  |  90 天  Win10 企业版 LTSB版 14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISE ...

  3. redis学习笔记——数据类型

    对象处理机制 Redis 构建了自己的类型系统,这个系统的主要功能包括:• redisObject 对象.• 基于redisObject 对象的类型检查.• 基于redisObject 对象的显式多态 ...

  4. 当php懈垢windows通用上传缺陷

    转自独自等待博客 早上逛乌云发现了PKAV大牛的一篇文章,针对php和windows文件上传的分析,思路很YD,果断转之与大家分享. 虽然此文可能有许多的限制条件,但是如果你认真阅读会发现,其实还是比 ...

  5. Python学习笔记(一)类和继承的使用

    一年前就打算学Python了,折腾来折腾去也一直没有用熟练,主要是类那一块不熟,昨天用Python写了几个网络编程的示例,感觉一下子迈进了很多.这几天把学习Python的笔记整理一下,内容尽量简洁. ...

  6. [经验总结]material design效果与开发总结

    首先贴一个參考过的文章,写的不错: 在低版本号android系统上实现Material design应用 以下是工作中总结出来的,列出了在<5.0的设备是怎样实现material design的 ...

  7. android 通过bitmapfactory得到图片真实像素的方法,以及没有得到真实像素的原因

    原文来自:原文地址 由于这个错误导致浪费非常长时间找原因,所以要赶紧记录下来. 过程是这种,在使用android读取图片的时候,就是使用BitmapFactory.decodeResource(thi ...

  8. EFFECTIVE JAVA 第一天 静态工厂方法

    静态工厂方法:(这里指的是就是普通static方法),类可以通过静态工厂方法提供给它的客户端,而不是通过构造器.提供静态工厂方法而不是公有构造器,这样做有几大优势. 在类的实现中使用了API的类被称为 ...

  9. KingdeeK3-修改单据邮件发送的自定义字段

    只需要执行类似下面语句即可: update ICTemplateentry set FVisForBillType = 63,flookupcls=6 where fid ='P01' and fhe ...

  10. svn client命令

    经常使用svn命令说明 1.从SVN仓库中检索出代码到工作拷贝: # svn checkout https://svn.sinaapp.com/appname [workcopy] 当中workcop ...