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. ...
随机推荐
- 【每日一记】unity3d 图片置灰shader
项目须要.參考了一下网上的资料,写了一个shader,给button置灰. shader详细实现例如以下: 2016.07.25补充,支持mask剪裁 Shader "Transparent ...
- sublime搜索和替换--多文件搜索替换
Search and Replace - Multiple Files Searching To open the search panel for files, press Ctrl + Shift ...
- node05---模块
Node.js开发服务器,数据.路由.本地关心的效果,交互: Node.js实际上是极客开发出的一个小玩具,不是银弹.有着别人不具备的怪异特点: 首先,Node不为每个用户开辟一个线程,所以非常单线程 ...
- zzulioj--1813--good string(模拟)
1813: good string Time Limit: 1 Sec Memory Limit: 128 MB Submit: 93 Solved: 15 SubmitStatusWeb Boa ...
- hdoj--1556--Color the ball(模拟&&树状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Android控件postDelayed用法,View自带的定时器
有一个需求是这样的,点击加关注按钮后,执行关注操作,成功后按钮文字变为“已关注”,保持3秒,三秒后按钮文字便问“取消关注”,点击后执行取消关注的操作 源码: public boolean postDe ...
- 关于servlet的@WebServlet注解
@WebServlet注解用于标注在一个继承了HttpServlet类之上,属于类级别的注解. 1.jsp页面 通过action提交到RegistServlet 类: <form action= ...
- 51Nod 1007 正整数分组(01背包)
将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的. Input 第1行:一个数N,N为正整数的数量. ...
- 编译报错一列----aclocal找不到
编译源码包报错: 说aclocal这个命令找不到 解决: 使用 yum install -y automake问题解决
- NSURLSession的作用
NSURLSession的作用: 1.全局配置: 2.任务生成与管理: 3.数据链接管理: po self.urlSession.delegateQueue.operations <__NSAr ...