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

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

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

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

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

代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. const int M = 1100;
  5. using namespace std;
  6.  
  7. struct node{
  8. int l, r;
  9. }s[M];
  10. int n;
  11. bool vis[M];
  12.  
  13. bool cmp(node a, node b){
  14. return a.r < b.r;
  15. }
  16.  
  17. int f(double x){
  18. memset(vis, 0, sizeof(vis));
  19. int res = 0;
  20. for(double d = x; d < M; d += 5){
  21. for(int i = 0; i < n; ++ i){
  22. if(!vis[i]&&d > s[i].l &&s[i].r > d){
  23. res++;
  24. vis[i] = 1; break;
  25. }
  26. }
  27. }
  28. return res;
  29. }
  30.  
  31. int main(){
  32. while(scanf("%d", &n), n){
  33. for(int i = 0; i < n; ++ i) scanf("%d%d", &s[i].l, &s[i].r);
  34. sort(s, s+n, cmp);
  35. int ans = 0;
  36. for(double i = 0.5; i < 5; ++ i){
  37. ans = max(ans, f(i));
  38. }
  39. printf("%d\n", ans);
  40. }
  41. return 0;
  42. }

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. WebSocket 的一些简单页面推送使用

    因为做通信项目的时候,需要实时获取每个分机的当前状态,发现websocket还不错,只是对浏览器的要求比较高, 针对特定用户推送消息,网上有一些 public class GetHttpSession ...

  2. QList模板类常用接口函数

    插入操作:insert()函数原型:void QList::insert(int i, const T &value) 在索引后插入值 i:索引 value:插入值 Example: QLis ...

  3. Mysql,Oracle使用rollup函数完成行列统计

    时间 2014-02-25 00:05:38  ITeye-博客 原文  http://53873039oycg.iteye.com/blog/2021445 主题 MySQLOracle数据库 昨天 ...

  4. LeetCode1-5

    Leetcode1: Given an array of integers, return indices of the two numbers such that they add up to a ...

  5. ERROR 1133 (42000): Can't find any matching row in the user table

    环境:操作系统:Redhat 7.5 x86-64 数据库版本MySQL 5.7.25 现象:ERROR 1133 (42000): Can't find any matching row in th ...

  6. css hack解决方案

    现在大家做项目的时候估计很多都已经不怎么考虑兼容问题,大多数的公司都已经舍弃ie7.8了,都是从ie9+开始,所以说不会有那么多的兼容问题需要去解决了,但是由于本人力求完美的工作习惯,做项目的时候还是 ...

  7. 安装配置Keepalived

    一.在haproxy容器安装Keepalived 1.进入haproxy容器: docker exec -it h1 bash 2.apt-get update(因为haproxy容器为Ubuntu) ...

  8. assert.throws()函数详解

    assert.throws(block[, error][, message]) Node.js FS模块方法速查 期望 block 函数抛出一个错误. 如果指定 error,它可以是一个构造函数.正 ...

  9. linux文件及目录的权限管理

    一.文件的权限 1.文件权限的查看 命令:ls -l 可以使用ll命令代替 ls -l 2.ls -l 所包含的信息 (1)权限信息 (-rw-r--r-- ) 一共有10位 a.第一位:表示文件信息 ...

  10. rbac组件之数据库设计(一)

    rbac是基于角色的权限设计,一共包含六张表,具体的表设计如下: from django.db import models class Menu(models.Model): "" ...