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. 7.1 - CRM系统

    一.简介 crm 客户关系管理软件 ( Customer Relationship Management ) ( 详细内容 ) stark组件(仿admin组件)( 详细内容 ) rbac组件(基于角 ...

  2. Python开发【Django】:CMDB基础

    浅谈ITIL TIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central ...

  3. Day07 jdk5.0新特性&Junit&反射

    day07总结 今日内容 MyEclipse安装与使用 JUnit使用 泛型 1.5新特性 自动装箱拆箱 增强for 静态导入 可变参数方法 枚举 反射 MyEclipse安装与使用(yes) 安装M ...

  4. mysql 数据操作 单表查询 having 过滤

    SELECT 字段1,字段2... FROM 库名.表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 1.首先找到表 库.表 ...

  5. C#基础笔记(第九天)

    1.面向过程<-->面向对象面向过程:面向的是完成这件事儿的过程,强调的是完成这件事儿的动作. 面向对象:找个对象帮你做事儿.意在写出一个通用的代码,屏蔽差异. 每个人都有姓名,性别,身高 ...

  6. JAVA优化技巧分享 让游戏更加的流畅

    我的世界怎么样可以玩的更加流畅呢?怎么对游戏进行优化呢?相信很多小伙伴都很想知道吧,今天小编为大家带来的是我的世界游戏优化技巧,喜欢的小伙伴不要错 ... 在很多时候如果电脑配置过低的话,玩游戏并不流 ...

  7. sdut AOE网上的关键路径(spfa+前向星)

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2498&cid=1304 题目描述 一个无环的有向图称为无环图(Directed Acyc ...

  8. html编码常见的有utf-8和gb2312编码等,应该如何判断选择?

    html如何选择编码,常见utf-8和gb2312编码如何判断选择 一.首先了解目前国内中文网页常用编码是utf-8 还是gb2313. 比如: 百度搜索 网页使用utf-8 腾讯新闻 网页使用utf ...

  9. VS2010/MFC编程入门之二十一(常用控件:编辑框Edit Control)

    鸡啄米上一节讲了静态文本框,本节要讲的编辑框(Edit Control)同样是一种很常用的控件,我们可以在编辑框中输入并编辑文本.在前面加法计算器的例子中已经演示了编辑框的基本应用.下面具体讲解编辑框 ...

  10. JavaScript进阶内容笔记1:各种对象类型判断

    该文章主要用来介绍JavaScript中常用的一些对象检测判断方法,整理资源来自书本和网络,如有错误或说明不详之处,望评论提出,本菜定提名感谢……(本文章知识比较基础,大牛请提些意见再绕道,三克油^_ ...