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. MVC 附件在线预览

    原因:应客户需求,在系统中浏览附件内容,需要先下载到本地然后打开,对使用造成了不便,要求可以不需下载直接在浏览器中打开减少操作步骤. 领导给了3天时间,最后查找方法,写测试项目,往正式项目添加,测试, ...

  2. node.js入门之三

    Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux ...

  3. Log4j 配置某个类中某个方法的输出日志到指定文件

    我们在项目中使用log4j开发的时候,会遇到一些特殊的情况,比如:要输出某个类中某个方法的日志信息到文件中,方便以后查看 可以使用如下配置: log4j.rootLogger=info,stdout ...

  4. CREATE DATABASE - 创建新数据库

    SYNOPSIS CREATE DATABASE name [ [ WITH ] [ OWNER [=] dbowner ] [ LOCATION [=] 'dbpath' ] [ TEMPLATE ...

  5. basename - 从文件名中剥离目录和后缀

    总览 (SYNOPSIS) basename NAME [SUFFIX] basename OPTION 描述 (DESCRIPTION) 显示 去掉 目录成分 后的 NAME. 如果 指定了 SUF ...

  6. html引用ttf字体文件

    在样式表如此定义: @font-face { font-family: MyFontName;//自定义字体名称 src: url(../Gloss_And_Bloom.ttf) } 然后,具体使用: ...

  7. 15数据库与ADO.Net

    数据库与ADO.Net 数据库与ADO.Net 8.1   数据库基本概念 数据库提供了一种将信息集合在一起的方法.数据库应用系统主要由三部分组成:数据库管理系统(DBMS),是针对所有应用的,例如A ...

  8. 富文本编辑器复制Wod字体问题

    目前常用的富文本编辑器:百度版UEditor,wangEditor,ckeditor,kindeditor,TinyMCE.当Word复制文本粘贴到编辑器时,几乎都无法保证字体大小完全一致的问题. 想 ...

  9. PyTorch: 序列到序列模型(Seq2Seq)实现机器翻译实战

    版权声明:博客文章都是作者辛苦整理的,转载请注明出处,谢谢!http://blog.csdn.net/m0_37306360/article/details/79318644简介在这个项目中,我们将使 ...

  10. ios中摄像头/相册获取图片压缩图片上传服务器方法总结

    本文章介绍了关于ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结,有需要了解的同学可以参考一下下.     这几天在搞iphone上面一个应用的开发,里面有需要摄像头/相册编程和图片上传的问 ...