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. 学习嵌入式开发板的Android平台体系结构和源码结构

    本文转自迅为论坛资料:http://www.topeetboard.com 推荐学习嵌入式开发板平台:iTOP-4412开发板 下面这张图出自Google官方,展示了Android系统的主要组成部分. ...

  2. 在死循环中使用Scanner获得键盘输入

    1. 编译时无错误和警告,且运行过程中无异常的代码示例 //编译时无错误和警告,且运行过程中无异常的代码示例package scanner_test; import java.util.*; publ ...

  3. jQuery 冒泡事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. gym100825G. Tray Bien(轮廓线DP)

    题意:3 * N的格子 有一些点是坏的 用1X1和1X2的砖铺有多少种方法 题解:重新学了下轮廓线 写的很舒服 #include <bits/stdc++.h> using namespa ...

  5. 【BIEE】新建用户,并且赋予组BIconsumer,访问BIpublisher报表报错:检索数据xml时出错

    问题描述 今天新建一个用户用户查看报表,并且赋予该用户属于BIConsumer组,但是在访问报表的时候出现以下两个错: 1.xdo格式类的报表 2.RTF模板制作的报表 解决方案: 出现这个问题的原因 ...

  6. 11-2 numpy/pandas/matplotlib模块

    目录 numpy模块 一维数组 二维数组 列表list和numpy的区别 获取多维数组的行和列 多维数组的索引 高级功能 多维数组的合并 通过函数方法创建多维数组 矩阵的运算 求最大值最小值 nump ...

  7. 第1节 hive安装:2、3、4、5、(多看几遍)

    第1节 hive安装: 2.数据仓库的基本概念: 3.hive的基本介绍: 4.hive的基本架构以及与hadoop的关系以及RDBMS的对比等 5.hive的安装之(使用mysql作为元数据信息存储 ...

  8. [转载]C++、C#写的WebService相互调用

    [转载]C++.C#写的WebService相互调用   首先感谢永和兄提供C++的WebService服务器端及客户端,并且陪我一起熬夜:然后是火石和我做接口的兄弟,虽然都不知道你叫什么,如果没有你 ...

  9. DHCP和PXE

    继续学习,Let's go!DHCP和PXE都是什么呢?如果非科班出身,可能一脸懵逼,好多东西需要去学习了,真的,继续学吧,付出不一定会有回报,不付出肯定就是等死了,呵呵! 一.DHCP 真正需要手动 ...

  10. xshell连接不了虚拟机处理方法(错误提示:Connection closing...Socket close.Connection closed by foreign host.Disconnected from remote host(localhost) at 08:47:23.)

    一.问题描述:xshell连接不了虚拟机,出现错误提示:Connection closing...Socket close.Connection closed by foreign host.Disc ...