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
58 3 5 3
1
58 1 5 3
4
40 6 10 2
50 9 10 2
60 3 4 2
70 1 4 2
4
42 6 10 2
50 9 10 2
54 3 4 2
70 1 4 2
4
30 6 10 2
50 9 10 2
54 3 4 2
70 1 4 2

Sample Output

65
63
280
274
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.

解题:贪心

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

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

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct node {
int s,t,a,d;
bool operator<(const node &x) const {
if(a == x.a) return t < x.t;
return a < x.a;
}
} course[maxn];
int n;
bool used[maxn];
priority_queue<node>q;
bool cmp(const node &x,const node &y) {
return x.t < y.t;
}
int main() {
int ret;
bool flag;
while(~scanf("%d",&n)) {
memset(used,false,sizeof used);
flag = true;
while(!q.empty()) q.pop();
for(int i = ret = ; i < n; ++i)
scanf("%d %d %d %d",&course[i].s,&course[i].t,&course[i].a,&course[i].d);
sort(course,course+n,cmp);
for(int i = ; i < n; ++i) {
for(int j = course[i].t; course[i].a > && j > && course[i].s < ; --j) {
if(!used[j]) {
used[j] = true;
course[i].s = min(,course[i].s + course[i].a);
course[i].a = max(,course[i].a - course[i].d);
}
}
if(course[i].s < ) {
flag = false;
break;
} else q.push(course[i]);
}
while(flag && !q.empty()) {
node now = q.top();
q.pop();
if(now.s == || now.a == ) {
ret += now.s;
continue;
}
bool mark = false;
for(int i = now.t; i > ; --i) {
if(!used[i]) {
mark = used[i] = true;
now.s = min(,now.s + now.a);
now.a = max(,now.a - now.d);
break;
}
}
if(mark) q.push(now);
else ret += now.s;
}
if(flag) printf("%d\n",ret);
else puts("you are unlucky");
}
return ;
}

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. 12、NIO、AIO、BIO二

    一.NIO2快速读写文件 写完之后记得flush一下,NIO2不能自行创建文件,需要在文件中判断一下. package com.zxc.L; import org.junit.Test; import ...

  2. Git(三):加入与提交

     在这一节.接着使用上一节的代码样例往下讲,http://blog.csdn.net/troy__/article/details/39806245. 加入文件到暂存区      加入新文件和改动版本 ...

  3. Linux多线程实践(六)使用Posix条件变量解决生产者消费者问题

    前面的一片文章我们已经讲过使用信号量解决生产者消费者问题.那么什么情况下我们须要引入条件变量呢? 这里借用  http://www.cnblogs.com/ngnetboy/p/3521547.htm ...

  4. Oozie框架基础

    * Oozie框架基础 官方文档地址:http://oozie.apache.org/docs/4.0.0/DG_QuickStart.html 除Oozie之外,类似的框架还有: ** Zeus:h ...

  5. 一些 <link> 标记分享

    <link rel="alternate" media="handheld" href="#" /> <link rel= ...

  6. 服务器TCP连接中 TIME_WAIT 状态过多

    今天查看服务器的TCP连接数,发现其中 TIME_WAIT 状态的太多了: # netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a ...

  7. 把qtdesigner中的ui文件生成py文件 anaconda

    无奈,马上实习就要结束了,但是自己的长进才是在stm32方面,虽然对linux有了些接触 但本质上没有任何进展,不能不说这事我的悲哀,在研三的时候却要做别人大二时做的事情 如今又是精力太散,迷上了py ...

  8. 快速创建WCF服务和svcutil.exe工具使用

    先简单的创建WCF服务: 系统会自动加上IService1接口 和 Service1 实现类 分别在IService1 和Service1 加上2段代码. [ServiceContract] publ ...

  9. HDU 4309 Seikimatsu Occult Tonneru

    Seikimatsu Occult Tonneru Time Limit: 6000ms Memory Limit: 32768KB This problem will be judged on HD ...

  10. Linux下切换python版本

    http://www.cnblogs.com/rhjeans/p/5499193.html