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. Swift 中关于”??”操作符

    Swift 中关于”??”操作符 Swift 的语法在保证安全和健壮的基础上,又带有很多非常灵活的特性,比如 ?? 操作符就是其中一个.大家可能已经了解它,也可能有些同学不了解它,这里给大家整理了关于 ...

  2. c# 任务超时执行

    最近整理下各类框架,学习一下欠缺的东西.因为前一年开发过java服务端,知道java有很多开源框架,但是毕竟起来也很累. 现在转回头从新审视c#,很基础,没有开源框架,因为以前它不开源,所以少,不用比 ...

  3. jwplayer

    将JW Player嵌入到网页中非常的简单,只需要进行如下3个步骤: 1.解压mediaplayer-viral.zip文件,将jwplayer.js和player.swf文件拷贝到工程中: 2.在页 ...

  4. multimap的使用

    multimap由于允许有重复的元素,所以元素插入.删除.查找都与map不同. 插入insert(pair<a,b>(value1,value2)) #include <iostre ...

  5. POJ 2007--Scrambled Polygon(计算凸包,点集顺序)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10094   Accepted: 476 ...

  6. C++的句柄类

    上一篇文件介绍了关于C++代理类的使用场景和实现方法,但是代理类存在一定的缺陷,就是每个代理类会创建一个新的对象,无法避免一些不必要的内存拷贝,本篇文章引入句柄类,在保持代理类多态性的同时,还可以避免 ...

  7. javascript--鼠标拖拽窗口案例(鼠标按下,在鼠标移动过程中,盒子跟着一起移动,鼠标松开,盒子停止移动)

    界面如图所示: 要求:在“信息注册”栏,按下鼠标,然后鼠标在页面移动,在鼠标移动过程中,该窗口跟着鼠标移动,当鼠标松开的时候,窗口停止移动.点击“关闭”,该窗口隐藏. 实现思路: 1.页面结构分析:一 ...

  8. python的pymysql模块简介

    一.介绍 在python中用pymysql模块来对mysql进行操作,该模块本质就是一个套接字客户端软件,使用前需要事先安装 pip3 install pymysql 二.操作简介 import py ...

  9. background兼容IE9以下版本

    .box {    width:100%;    height:80%;        background: url('img/nav_bg.png') no-repeat;    backgrou ...

  10. spring的事务处理

    说到事务,无非就是事务的提交commit和回滚rollback. 事务是一个操作序列,这些操作要么全部都执行成功,事务去提交,要么就是有一个操作失败,事务去回滚. 要知道事务的4大特性ACID.即原子 ...