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 (Ai,Bi). 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<=Ai<Bi<=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.

题目大意:给n个课程,每个课程有一个选择时间段(ai, bi),只能在这个时间段里面选择。然后你可以在任何时刻开始选课,然后每隔5分钟可以选一门课,问最多选多少门课。

思路:首先开始是越早越好,在8分开始不如在3分就开始。然后枚举5个开始时间,然后对每个时间枚举可以选择的课,选bi最小的(因为bi最小的被后面的时间选中的可能性最小,若bi能在后面被选中那么其他也能在后面被选中)。完全暴力不需要任何优化即可AC。

PS:那个(ai, bi)应该是开区间,不过我们可以选择在0分1秒的时候开始,所以可以看成是[ai, bi)。

代码(31MS):

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = ; int a[MAXN], b[MAXN];
bool sel[MAXN];
int n; int solve() {
int ret = ;
for(int st = ; st < ; ++st) {
memset(sel, , sizeof(sel));
int ans = ;
for(int i = st; i <= ; i += ) {
int best = -;
for(int j = ; j < n; ++j)
if(!sel[j] && a[j] <= i && i < b[j]) {
if(best == -) best = j;
else if(b[j] < b[best]) best = j;
}
if(best != -) {
sel[best] = true;
++ans;
}
}
if(ret < ans) ret = ans;
}
return ret;
} int main() {
while(scanf("%d", &n) != EOF && n) {
for(int i = ; i < n; ++i) scanf("%d%d", &a[i], &b[i]);
printf("%d\n", solve());
}
}

HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)的更多相关文章

  1. 2010 Asia Fuzhou Regional Contest

    A hard Aoshu Problem http://acm.hdu.edu.cn/showproblem.php?pid=3699 用深搜写排列,除法要注意,还有不能有前导零.当然可以5个for, ...

  2. HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)

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

  3. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)

    Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...

  4. HDU 3698 Let the light guide us(DP+线段树)(2010 Asia Fuzhou Regional Contest)

    Description Plain of despair was once an ancient battlefield where those brave spirits had rested in ...

  5. HDU 3696 Farm Game(拓扑+DP)(2010 Asia Fuzhou Regional Contest)

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

  6. HDU 3697 Selecting courses(贪心)

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

  7. hdu 3697 Selecting courses (暴力+贪心)

    Selecting courses Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others ...

  8. HDU 3697 Selecting courses 选课(贪心)

    题意: 一个学生要选课,给出一系列课程的可选时间(按分钟计),在同一时刻只能选一门课程(精确的),每隔5分钟才能选一次课,也就是说,从你第一次开始选课起,每过5分钟,要么选课,要么不选,不能隔6分钟再 ...

  9. HDU - 3697 Selecting courses

    题目链接:https://vjudge.net/problem/HDU-3697 题目大意:选课,给出每门课可以的选课时间.自开始选课开始每过五分钟可以选一门课,开始 时间必须小于等于四,问最多可以选 ...

随机推荐

  1. java流汇总以及使用实例

    流一.基本概念 Java中对文件的操作是以流的方式进行的.流是Java内存中的一组有序数据序列.Java将数据从源(文件.内存.键盘.网络) 读入到内存中,形成了流,然后将这些流还可以写到另外的目的地 ...

  2. viewpager中 pagerAdapter使用详解

    必须覆盖以下方法instantiateItem(ViewGroup, int) 这个方法,return一个对象,这个对象表明了PagerAdapter适配器选择哪个对象*放在当前的ViewPager中 ...

  3. 整理 45 道 CSS 基础面试题(附答案)

    1.介绍一下标准的CSS的盒子模型?与低版本IE的盒子模型有什么不同的? 标准盒子模型:宽度=内容的宽度(content)+ border + padding + margin低版本IE盒子模型:宽度 ...

  4. SpringBoot非官方教程 | 第六篇:springboot整合mybatis

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot-mybatis/ 本文出自方志朋的博客 本文主要 ...

  5. ssm整合实现注册与登录功能

    最简洁易懂的SSM整合源码都在这里了 激情提示: 1.本项目是用IDEA编写的,不管你是习惯何种ide工具,那也只是工具而已,源代码才是本质 2.本项目只拥有注册和登录功能,简易的功能和详细的注释,是 ...

  6. 快速解决Kali 更新失败问题

    Kali Linux 2018.4 初学者在安装完kali 系统后第一件事往往就是更新软件,但在更新过程中通常会出现各种各样的问题,比如更新提示不含有 'maincontrib' 组件,跳过配置文件 ...

  7. 关于api接口

    前阵子一直疯狂的找关于php的api接口方面的资料来学习,总结了一下,无非就是请求数据,然后返回数据,当然也要设置相关安全措施,比如认证口令 等.返回数据格式是json 还是xml 看自己需求咯

  8. 人人都会设计模式:观察者模式--Observer

    https://segmentfault.com/a/1190000012295887 观察者模式是抽像通知者和观察者,达到具体通知者跟具体观察者没有偶合.能达到不管是切换通知者,或者是切换观察者,都 ...

  9. (译)JavaScript 中的正则表达式(RegEx)实操——快速掌握正则表达式,伴有随手可练的例子————(翻译未完待续)

    (原文:https://blog.bitsrc.io/a-beginners-guide-to-regular-expressions-regex-in-javascript-9c58feb27eb4 ...

  10. dijkstra算法学习

    dijkstra算法学习 一.最短路径 单源最短路径:计算源点到其他各顶点的最短路径的长度 全局最短路径:图中任意两点的最短路径 Dijkstra.Bellman-Ford.SPFA求单源最短路径 F ...