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
 
 
这道题有原题了...记得还是我贪心第一题呢
先优先起点然后优先长度,画个图比一比就能证明
 
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; const int maxn=550; struct node
{
int ai,bi;
} task[maxn];
int nn;
bool mark[maxn]; bool cmp(node A, node B)
{
if(A.bi==B.bi) return A.ai<B.ai;
return A.bi<B.bi;
} int solve(int ss)
{
int ans=0;
memset(mark,0,sizeof(mark));
for(int i=ss;i<=task[nn-1].bi;i+=5){
for(int j=0;j<nn;j++){
if(mark[j]) continue;
if(i>=task[j].ai&&i<task[j].bi){
ans++;
mark[j]=1;
break;
}
}
}
return ans;
} int main()
{
int ans;
while(scanf("%d",&nn),nn!=0){
for(int i=0;i<nn;i++) scanf("%d%d",&task[i].ai,&task[i].bi);
sort(task,task+nn,cmp);
ans=0;
for(int i=0;i<5;i++) ans=max(ans,solve(i));
printf("%d\n",ans);
}
}

  

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. Git 基本操作(二)

    1. 分支操作 1.1 Fast-forward 当被合并分支(C4)位于合并分支(C2)的历史线上,此时的合并称为"fast-forward"; // hotfix 被合并到 m ...

  2. paramiko与ssh

    一.paramiko模块的安装 paramiko模块依赖PyCrypto模块,而PyCrypto需要GCC库编译,不过一般发行版的源里带有该模块.这里以centos6为例,直接借助以下命令可以直接完成 ...

  3. windows下安装redis(转)

    add by zhj: redis相比memcached相比,性能上并没有绝对的优势.我们用redis的是因为它支持更多的数据类型,而且在分配给redis的内存用满了之后, redis也不会删除没有过 ...

  4. kubernetes实战(八):k8s集群安全机制RBAC

    1.基本概念 RBAC(Role-Based Access Control,基于角色的访问控制)在k8s v1.5中引入,在v1.6版本时升级为Beta版本,并成为kubeadm安装方式下的默认选项, ...

  5. MongDb的安装

    MongoDB是一个基于分布式文件存储的数据库,由c++语言编写,为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB属于非关系数据库,也不能说完全属于,更像是介于关系数据库和非关系数据库之 ...

  6. 001-spring cache 简介

    一.概述 参看地址: 自3.1版以来,Spring Framework提供了对现有Spring应用程序透明地添加缓存的支持.与事务支持类似,缓存抽象允许一致地使用各种缓存解决方案,而对代码的影响最小. ...

  7. Java转Exe

    1.Jsmooth Java文件打包成exe文件(可以在没安装JDK的环境下运行):http://www.tuicool.com/articles/byIFJn 2.用JSmooth制作java ja ...

  8. docker——网络配置

    一.网络启动与配置参数 Docker启动时会在主机上自动创建一个docker0虚拟网桥,实际上是一个Linux网桥,可以理解为一个软件交换机,它会在挂载其上的接口之间进行数据转发.同时,Docker随 ...

  9. Linux /python --- zipinfo命令

    Linux zipinfo命令用于列出压缩文件信息. 执行zipinfo指令可得知zip压缩文件的详细信息. zipinfo [-12hlmMstTvz][压缩文件][文件...][-x <范本 ...

  10. POJ 3259 Wormholes(最短路&spfa正权回路)题解

    题意:给你m条路花费时间(双向正权路径),w个虫洞返回时间(单向负权路径),问你他能不能走一圈回到原点之后,时间倒流. 思路:题意有点难看懂,我们建完边之后找一下是否存在负权回路,存在则能,反之不能. ...