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. ...
随机推荐
- C&C控制服务的设计和侦测方法综述——DDoS攻击,上传从宿主机偷窃的到的信息,定时给感染机文件加密勒索等。
这篇文章总结了一些我在安全工作里见到过的千奇百怪的C&C控制服务器的设计方法以及对应的侦测方法,在每个C&C控制服务先介绍黑帽部分即针对不同目的的C&C服务器设计方法,再介绍白 ...
- zzulioj--1825-- 会长爱数学(模拟)
1825: 会长爱数学 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 6 Solved: 2 SubmitStatusWeb Board Descr ...
- nfs共享文件服务搭建
网络文件共享服务器192.10.19.132yum install -y nfs-utils 在exports文件中添加的从机范围vim /etc/exports/home/nfs/ 192.10.1 ...
- Automation testing tool comparison - UFT & CodedUITest
Ease of Use - Recording and Playback Functionality UFT provides 4 models to record a new test. Norma ...
- 一些 <link> 标记分享
<link rel="alternate" media="handheld" href="#" /> <link rel= ...
- Spring MVC 核心架构图
架构图对应的DispatcherServlet核心代码如下: //前端控制器分派方法 protected void doDispatch(HttpServletRequest request, Htt ...
- Hello World基于.net framework中CLR的执行
static void Main(string[] args) { Console.WriteLine("Hello,World!"); Console.WriteLine(&qu ...
- linux指令快速复制粘贴[龟速更新中]
由于有经常碰到要输入linux指令,但是却忘记了的情况.在家里我把常用的命令放到Xshell的快速命令集,但是在很多情况下不在家,可能用的他人电脑,以及在非Win环境下使用ssh时没有xshell使用 ...
- Android SDK Manager代理设置
1.SDK Manager中打开 Tools—>Manage Add-on Sites…—>User Defined Sites 2.New …输入: http://android-mir ...
- POJ3904 Sky Code【容斥原理】
题目链接: http://poj.org/problem?id=3904 题目大意: 给你N个整数.从这N个数中选择4个数,使得这四个数的公约数为1.求满足条件的 四元组个数. 解题思路: 四个数的公 ...