CSUOJ 1603 Scheduling the final examination
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的更多相关文章
- Edward's Cola Plan
Edward's Cola Plan Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu S ...
- 杭电多校第九场 hdu6424 Rikka with Time Complexity 数学
Rikka with Time Complexity Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K ( ...
- Summarizing NUMA Scheduling两篇文章,解释得不错
http://vxpertise.net/2012/06/summarizing-numa-scheduling/ Sitting on my sofa this morning watching S ...
- 十三、springboot集成定时任务(Scheduling Tasks)
定时任务(Scheduling Tasks) 在springboot创建定时任务比较简单,只需2步: 1.在程序的入口加上@EnableScheduling注解. 2.在定时方法上加@Schedule ...
- Quartz Job scheduling 基础实现代码
Quartz 集成在 SpringBoot 中分为 config.task.utils.controller 和 MVC 的三层即 controller.service.dao 和 entity. c ...
- 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 ...
- HDU 6651 Final Exam (思维)
2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...
- SpringBoot中使用Scheduling执行定时任务
SpringBoot自带的 Schedule,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多 以下任务都是在单线程下执行的 第一步 创建SpringBoot项目 第二步 外汇 ...
- 注解配置定时器Scheduling
注解配置定时器配置 package com.demo; import org.springframework.context.annotation.Configuration; import org. ...
随机推荐
- nginx模块开发
开发方法參考淘宝的教程 这个模块的功能是向client发送一个文件,类似于网页上的另存为功能 #include <ngx_config.h> #include <ngx_core.h ...
- 里根上台时国债只占GDP的30%
学里根是刻舟求剑,关键是钱从哪来 5 里根主要靠借钱,这是冷战红利,美国打完二战国债占了GDP的120%,然后总量就没怎么增加,但战后GDP快速增长,结果国债占GDP的比例连续下降,打越战登月石油危 ...
- BZOJ 球形空间产生器 解题报告(高斯消元)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 有一个球形空间产生器能 ...
- CSRF的原理
CSRF是什么? (Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一,也被称为“One Click ...
- [学习笔记]node.js中的path.extname方法
path.extname 返回path路径文件扩展名,如果path以 ‘.' 为结尾,将返回 ‘.',如果无扩展名 又 不以'.'结尾,将返回空值. path.extname('index.html' ...
- 使用google API之前需要對input 做什麼 安全性的處理?
我正要使用node.js 和 google map api做一个小应用,Google MAP API的使用URL如下: https://maps.googleapis.com/maps/api/pla ...
- 《剑指offer》跳台阶
一.题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 二.输入描述 输入n级台阶 三.输出描述 输出总有多少种不同跳法 四.牛客网提供的框架 cla ...
- c# 的类成员
1 字段和变量的区别 字段是在类中定义的数据成员 由访问修饰符+数据类型+字段名(public string name) 字段就像类的一个小数据库,用来存放和类相关的数据; 而变量是没有修饰符的(in ...
- HDU I Hate It(线段树单节点更新,求区间最值)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分 ...
- UNIX 是什么?怎么诞生的?
要记住, 当一扇门在你面前关闭的时候, 另一扇门就会打开. 肯·汤普森(Ken Thompson) 和丹尼斯·里奇(Dennis Richie)两个人就是这句名言很好的实例.他们俩是20世纪最优秀的信 ...