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. ...
随机推荐
- tp5实现多数据库查询
引言: 有时候一个管理后台,需要涉及到多个数据库.比如,商城管理.直播管理.消息管理等等,它们都有自己的数据库.这个时候,就需要去连接多个数据库,进行处理了.thinkphp可以支持多个数据库连接. ...
- 10.Intellij IDEA svn的使用详解
转自:https://www.2cto.com/kf/201703/614858.html 首先提一句,IDEA对各种的版本控制工具的支持是非常好的,打开系统设置界面,就可以看到他有专门的一栏 Ver ...
- C#篇(一)——字段与属性
字段和属性有什么区别? class Student { private int age; public int Age { get { return age; } set { age = value; ...
- jsp输出当前时间
在jsp页面中输出完整的时间,格式为"年 月 日 时:分:秒" <% Date date = new Date(); SimpleDateFormat t = new Si ...
- Spring 注解拦截器使用详解
Spring mvc拦截器 平时用到的拦截器通常都是xml的配置方式.今天就特地研究了一下注解方式的拦截器. 配置Spring环境这里就不做详细介绍.本文主要介绍在Spring下,基于注解方式的拦截器 ...
- unbuntu禁用ipv6
ubuntu禁用ipv6cat /proc/sys/net/ipv6/conf/all/disable_ipv6 显示0说明ipv6开启,1说明关闭 在 /etc/sysctl.conf 增加下面几行 ...
- 排序算法(Apex 语言)
/* Code function : 冒泡排序算法 冒泡排序的优点:每进行一趟排序,就会少比较一次,因为每进行一趟排序都会找出一个较大值 时间复杂度:O(n*n) 空间复杂度:1 */ List< ...
- Windows7 安装ubuntu双系统
家里的老笔记本是MBR分区,不支持EFI , 一开始是用U盘安装的,还对着ubuntu官网的教程,下载了官方推荐的那个u盘引导工具,安装依然会报错, 网上查询也有很多种说法,也有说是bug的,无论如何 ...
- 【agc004f】Namori Grundy
那个问一下有人可以解释以下这个做法嘛,看不太懂QwQ~ Description 有一个n个点n条边的有向图,点的编号为从1到n. 给出一个数组p,表明有(p1,1),(p2,2),…,(pn,n)这n ...
- unity调用Android的两种方式:其二,调用aar包
上一篇我们讲了unity如何调用jar包 http://www.cnblogs.com/Jason-c/p/6743224.html, 现在我们介绍一下怎么生成aar包和unity怎么调用aar 一. ...