1603: Scheduling the final examination

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 49  Solved: 15

Description

For the most of the university students,what they most want is that they can obtain 60 points from the final examination of every subject. Now, final examination is coming. As an excellent programmer,you are asked for help. The full mark is 100, and it is need greater than or equal to 60 to pass subjects. Given the description of every subject, you should schedule the time of review to every subject in order to pass every subject and at the same time to obtain the higher total scores as possible.

Input

The input consists of multiple test cases. For each test case, the first line is an integer n (1<=n<=50), which is the number of subjects. Then n lines follow, each line has four integers si, ti, ai, di to describe the subject. si(0<=si<=100):the score that he can obtained without reviewing,ti(1<=ti<720):the time of examination,
ai(1<=ai<=40):the first hour reviewing on this subject will improve ai scores,di(0<=di<=4):the improving scores will decrease di every reviewing hour. For example,when ai = 10, di = 2, the first hour viewing will improve 10 scores , and the second hour viewing will only improve 8 scores.

Output

For each test case, to output in one line. If he can pass all the subjects, please output an integer which is the highest total scores, otherwise please output a string “you are unlucky”.

Sample Input

  1. 1
  2. 58 3 5 3
  3. 1
  4. 58 1 5 3
  5. 4
  6. 40 6 10 2
  7. 50 9 10 2
  8. 60 3 4 2
  9. 70 1 4 2
  10. 4
  11. 42 6 10 2
  12. 50 9 10 2
  13. 54 3 4 2
  14. 70 1 4 2
  15. 4
  16. 30 6 10 2
  17. 50 9 10 2
  18. 54 3 4 2
  19. 70 1 4 2

Sample Output

  1. 65
  2. 63
  3. 280
  4. 274
  5. you are unlucky

HINT

Please noting: every subject’ full scores is 100. So when you get a result of one subject which is bigger than 100, you should regard the result as 100.

解题:贪心

首先要保证都及格,按考试时间从小到大排序,设置一个时间占用的数组用以标记此时间是否被占用,然后对没及格的科目,从截至时间从后往前走,发现一个没被用的时间,就占用该时间,直到及格。

然后用优先队列,优先选择当前能获得分数最高的先复习,同样是从截至时间往前走,遇到没占用的,直接占用,跳出循环。如果有多个最高值,直接选择截至时间靠前的。。。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = ;
  4. struct node {
  5. int s,t,a,d;
  6. bool operator<(const node &x) const {
  7. if(a == x.a) return t < x.t;
  8. return a < x.a;
  9. }
  10. } course[maxn];
  11. int n;
  12. bool used[maxn];
  13. priority_queue<node>q;
  14. bool cmp(const node &x,const node &y) {
  15. return x.t < y.t;
  16. }
  17. int main() {
  18. int ret;
  19. bool flag;
  20. while(~scanf("%d",&n)) {
  21. memset(used,false,sizeof used);
  22. flag = true;
  23. while(!q.empty()) q.pop();
  24. for(int i = ret = ; i < n; ++i)
  25. scanf("%d %d %d %d",&course[i].s,&course[i].t,&course[i].a,&course[i].d);
  26. sort(course,course+n,cmp);
  27. for(int i = ; i < n; ++i) {
  28. for(int j = course[i].t; course[i].a > && j > && course[i].s < ; --j) {
  29. if(!used[j]) {
  30. used[j] = true;
  31. course[i].s = min(,course[i].s + course[i].a);
  32. course[i].a = max(,course[i].a - course[i].d);
  33. }
  34. }
  35. if(course[i].s < ) {
  36. flag = false;
  37. break;
  38. } else q.push(course[i]);
  39. }
  40. while(flag && !q.empty()) {
  41. node now = q.top();
  42. q.pop();
  43. if(now.s == || now.a == ) {
  44. ret += now.s;
  45. continue;
  46. }
  47. bool mark = false;
  48. for(int i = now.t; i > ; --i) {
  49. if(!used[i]) {
  50. mark = used[i] = true;
  51. now.s = min(,now.s + now.a);
  52. now.a = max(,now.a - now.d);
  53. break;
  54. }
  55. }
  56. if(mark) q.push(now);
  57. else ret += now.s;
  58. }
  59. if(flag) printf("%d\n",ret);
  60. else puts("you are unlucky");
  61. }
  62. return ;
  63. }

CSUOJ 1603 Scheduling the final examination的更多相关文章

  1. Edward's Cola Plan

     Edward's Cola Plan Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu S ...

  2. 杭电多校第九场 hdu6424 Rikka with Time Complexity 数学

    Rikka with Time Complexity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K ( ...

  3. Summarizing NUMA Scheduling两篇文章,解释得不错

    http://vxpertise.net/2012/06/summarizing-numa-scheduling/ Sitting on my sofa this morning watching S ...

  4. 十三、springboot集成定时任务(Scheduling Tasks)

    定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...

  5. Quartz Job scheduling 基础实现代码

    Quartz 集成在 SpringBoot 中分为 config.task.utils.controller 和 MVC 的三层即 controller.service.dao 和 entity. c ...

  6. spark 笔记 3:Delay Scheduling: A Simple Technique for Achieving Locality and Fairness in Cluster Scheduling

    spark论文中说他使用了延迟调度算法,源于这篇论文:http://people.csail.mit.edu/matei/papers/2010/eurosys_delay_scheduling.pd ...

  7. HDU 6651 Final Exam (思维)

    2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...

  8. SpringBoot中使用Scheduling执行定时任务

    SpringBoot自带的 Schedule,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多 以下任务都是在单线程下执行的 第一步 创建SpringBoot项目 第二步 外汇 ...

  9. 注解配置定时器Scheduling

    注解配置定时器配置 package com.demo; import org.springframework.context.annotation.Configuration; import org. ...

随机推荐

  1. leetCode(38):Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  2. 转:百分百激活office for mac2011的激活文件

    方法:1点击finder             2点击系统盘             3点击资源库             4找到Preferences文件夹             5用压缩包里的 ...

  3. 【SSH 基础】浅谈Hibernate关系映射(3)

    继上篇博客 一对多关联映射(单向) 上面我们介绍了多对一,我们反过来看一对多不就是多对一吗?那还用再进行不同的映射吗?有什么区别吗?一对多和多对一映射原理是一致的,存储是同样的.也就是生成的数据库的表 ...

  4. iPad iOS8.0升级和Xcode 6.0.1公布了,附Xcode 6.0.1下载地址

    今天上午把iPad mini升级到了iOS 8.0,升级提示须要6.7G空间,无奈仅仅好把一些大的App删掉腾冲空间,然后開始升级,3小时后最终升级成功了. 下午试着把我们的App通过xcode 5 ...

  5. Mvc 返回文件直接下载

    今天碰到一个问题,前端点击下载文件,后端判断文件是否存在,不存在则自动生成文件(图片),返回前端会自动下载文件 网上查了一些  Mvc  action中返回File类型 设置一些contentType ...

  6. Hadoop框架基础(三)

    ** Hadoop框架基础(三) 上一节我们使用eclipse运行展示了hdfs系统中的某个文件数据,这一节我们简析一下离线计算框架MapReduce,以及通过eclipse来编写关于MapReduc ...

  7. java 通过httpclient调用https 的webapi

    java如何通过httpclient 调用采用https方式的webapi?如何验证证书.示例:https://devdata.osisoft.com/p...需要通过httpclient调用该接口, ...

  8. codeforces 501 B Misha and Changing Handles 【map】

    题意:给出n个名字变化,问一个名字最后变成了什么名字 先用map顺着做的,后来不对, 发现别人是将变化后的那个名字当成键值来做的,最后输出的时候先输出second,再输出first 写一下样例就好理解 ...

  9. nginx的Rewrite重写

        location /{                if ($remote_addr=192.168.1.100){                          //禁止此 ip 访问 ...

  10. Java Web Application——servlet

    概述 是一个部署于web服务器中的实现了servlet接口的Java类,用于响应web请求 Web容器(也称为servlet容器)本质上是与servlet交互的Web服务器的组件.Web容器负责管理s ...