Selecting courses

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

Total Submission(s): 2082    Accepted Submission(s): 543

Problem 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.
 
Sample Input
2
1 10
4 5
0
 
Sample Output
2

题意:有n门课,选课时有以下rule:

1:每种课都有起始和结束,必须在之内选取。

2:每次选取之后5分钟后不能再选课。

先依照结束时间从小到大排序,由于是每过五分钟才干够选。那么我们仅仅须要枚举前四个时间,看是否在课程的起始与结束时间之内。就能够了。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
const int M = 1100;
using namespace std; struct node{
int l, r;
}s[M];
int n;
bool vis[M]; bool cmp(node a, node b){
return a.r < b.r;
} int f(double x){
memset(vis, 0, sizeof(vis));
int res = 0;
for(double d = x; d < M; d += 5){
for(int i = 0; i < n; ++ i){
if(!vis[i]&&d > s[i].l &&s[i].r > d){
res++;
vis[i] = 1; break;
}
}
}
return res;
} int main(){
while(scanf("%d", &n), n){
for(int i = 0; i < n; ++ i) scanf("%d%d", &s[i].l, &s[i].r);
sort(s, s+n, cmp);
int ans = 0;
for(double i = 0.5; i < 5; ++ i){
ans = max(ans, f(i));
}
printf("%d\n", ans);
}
return 0;
}

Hdoj 3697 Selecting courses 【贪心】的更多相关文章

  1. HDU 3697 Selecting courses(贪心)

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

  2. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

  3. HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

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

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

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

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

  6. HDU - 3697 Selecting courses

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

  7. poj 2239 Selecting Courses (二分匹配)

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8316   Accepted: 3687 ...

  8. poj——2239 Selecting Courses

    poj——2239   Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10656   A ...

  9. POJ-2239 Selecting Courses,三维邻接矩阵实现,钻数据空子。

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K       Description It is well known that ...

随机推荐

  1. Winform webbrowser 隐藏 html 元素

    目的:用webbrowser打开网页,并隐藏网页上某个html元素 1.如果已知元素ID,比较好办 直接使用webbrowser1.Document.getElementById("id&q ...

  2. struts2 针对类型转换出错的处理

    在类型转换出错时,需要在页面上显示友好提示: 类型转换出错时,会抛出一个运行时异常,程序会根据建立的属性文件,显示相应的错误提示. 实现方法: 1)新建局部属性文件或者全局属性文件 局部属性文件:放置 ...

  3. PowerDesigner连接MySQL数据库

    详细步骤请点击下面的链接查看! 我在网上找了很多篇教程, 其中这一篇是最好的. 可以成功的帮助我们把PowerDesigner和MySQL数据库相连. PowerDesigner真的非常强大! 设计数 ...

  4. QT5:先导篇 正则表达式

    一.简介 使用正则表达式可以快速完成处理字符串的一些操作,如验证 查找 替换和分割 Qt的QRegExp类是正则表达式的表示类,它基于Perl的正则表达式语言 正则表达式由表达式(expression ...

  5. 记录一次通过命令行方式来使用svn碰到的一系列问题

    由于使用Xcode自带的svn管理碰到很多问题,搞得头昏脑胀,找资料时看到小码哥这方面的视频,看完就开始折腾了. 准备:1.远程仓库地址及授权账号(用户名和密码) 2.一份项目代码,之所以要有这份代码 ...

  6. 使用sphinx

    SQL   结构化查询语言(是一种标准,所有的关系型数据库Mysql,sqlserver,oracle) sphinx的使用两种方式: 第一种:  使用sphinx的API来操作sphinx   (常 ...

  7. Vue如何mock数据模拟Ajax请求

    我们在做一个项目时前期可能没有后端提供接口模拟数据,那么作为前端就需要自己写json文件模拟数据加载.网上往往参考的都是不全面的,比如get请求没问题但是post请求就报错了.在Vue中只需要vue- ...

  8. POJ 3469 网络流最小割

    将两个CPU分别视作源点和汇点 对于那些不在同一个CPU中的模块会产生的代价作为一条双向的容量弧 这里每个模块可以在任意一个CPU中运行,相当于寻找一个割,分割后,在S集合中的模块安装在第一个CPU中 ...

  9. [luoguP1896] [SCOI2005]互不侵犯King(状压DP)

    传送门 先预处理出来一行中放置国王的所有情况和每种情况所用的国王个数. f[i][j][k]表示前i行放j个国王且最后一行的状态为k的方案数 状压DP即可 #include <cstdio> ...

  10. POJ 1988相对偏移

    //不容易啊,终于自己a了一道这种类型的题 // #include<stdio.h> #include<iostream> using namespace std; const ...