Description

    A new Semester is coming and students are troubling for selecting courses. Students select their course on the web course system. There are n courses, the ith course is available during the time interval (A i,B i). That means, if you want to select the ith course, you must select it after time Ai and before time Bi. Ai and Bi are all in minutes. A student can only try to select a course every 5 minutes, but he can start trying at any time, and try as many times as he wants. For example, if you start trying to select courses at 5 minutes 21 seconds, then you can make other tries at 10 minutes 21 seconds, 15 minutes 21 seconds,20 minutes 21 seconds… and so on. A student can’t select more than one course at the same time. It may happen that no course is available when a student is making a try to select a course

You are to find the maximum number of courses that a student can select.

 

Input

There are no more than 100 test cases.

The first line of each test case contains an integer N. N is the number of courses (0<N<=300)

Then N lines follows. Each line contains two integers Ai and Bi (0<=A i<B i<=1000), meaning that the ith course is available during the time interval (Ai,Bi).

The input ends by N = 0.

 

Output

For each test case output a line containing an integer indicating the maximum number of courses that a student can select. 
 

Sample Input

2
1 10
4 5
0
 

Sample Output

2
 
 
这道题有原题了...记得还是我贪心第一题呢
先优先起点然后优先长度,画个图比一比就能证明
 
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. const int maxn=550;
  10.  
  11. struct node
  12. {
  13. int ai,bi;
  14. } task[maxn];
  15. int nn;
  16. bool mark[maxn];
  17.  
  18. bool cmp(node A, node B)
  19. {
  20. if(A.bi==B.bi) return A.ai<B.ai;
  21. return A.bi<B.bi;
  22. }
  23.  
  24. int solve(int ss)
  25. {
  26. int ans=0;
  27. memset(mark,0,sizeof(mark));
  28. for(int i=ss;i<=task[nn-1].bi;i+=5){
  29. for(int j=0;j<nn;j++){
  30. if(mark[j]) continue;
  31. if(i>=task[j].ai&&i<task[j].bi){
  32. ans++;
  33. mark[j]=1;
  34. break;
  35. }
  36. }
  37. }
  38. return ans;
  39. }
  40.  
  41. int main()
  42. {
  43. int ans;
  44. while(scanf("%d",&nn),nn!=0){
  45. for(int i=0;i<nn;i++) scanf("%d%d",&task[i].ai,&task[i].bi);
  46. sort(task,task+nn,cmp);
  47. ans=0;
  48. for(int i=0;i<5;i++) ans=max(ans,solve(i));
  49. printf("%d\n",ans);
  50. }
  51. }

  

hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0的更多相关文章

  1. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  2. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  3. hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  4. hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0

    Description “Farm Game” is one of the most popular games in online community. In the community each ...

  5. hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1

    In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the t ...

  6. hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1

    F - Rotational Painting Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  8. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  9. HDU 3697 Selecting courses(贪心)

    题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...

随机推荐

  1. 【Loadrunner】使用LR录制HTTPS协议的三种方法

    使用LR录制HTTPS协议的三种方法 一.最简单的方法:浏览器配置打开浏览器,安装证书,配置完成后直接用http协议录制即可(配置完成的标识就是打开网页,不显示安全提示) 二.LR配置修改操作步骤如下 ...

  2. tools-eclipse-004-UML图安装

    git:https://github.com/takezoe/amateras-modeler 下载:http://sourceforge.jp/projects/amateras/downloads ...

  3. OPENSSL编程 (secure shell, ssh)

    很好的 OPENSSL编程 教程,名字就叫“OPENSSL编程” 它里面还有很多关于密码学的东西. http://www.pengshuo.me http://www.pengshuo.me/2014 ...

  4. hdu 5187 快速幂 + 快速乘 值得学习

    就是以那个ai为分水岭,左边和右边都分别是单调增或单调减如图         就这四种情况,其中头两种总共就是两个序列,也就是从头到尾递增和从头到尾递减.         后两种方式就是把序列中德数分 ...

  5. cocos2dx 3.x 蒙板 遮罩 点击圆功能

    //注册触摸 EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create(); listener->onT ...

  6. [OpenCV入门教程之十二】OpenCV边缘检测:Canny算子,Sobel算子,Laplace算子,Scharr滤波器合辑

    http://blog.csdn.net/poem_qianmo/article/details/25560901 本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog ...

  7. HDU1059 二进制拆分优化多重背包

    /*问你能不能将给出的资源平分成两半,那么我们就以一半为背包,运行多重背包模版 但是注意了,由于个数过大,直接运行会超时,所以要用二进制拆分每种的个数*/ #include<stdio.h> ...

  8. SQL学习笔记之SQL查询练习题1

    (网络搜集) 0x00 表名和字段 –1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id ...

  9. 20145309李昊《网络对抗》MSF应用基础

    实验内容 掌握metasploit的基本应用方式1.主动攻击——ms08_0672.针对浏览器的攻击——ms11_0503.针对客户端的攻击——Adobe4.成功应用一个辅助模块——scanner/d ...

  10. 20155201 2016-2017-2 《Java程序设计》第三周学习总结

    20155201 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 - 第四章要点: 4.1类与对象 类定义时使用class关键词,基本模式为 class na ...