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 are that they can obtain points from the final examination o F every subject. Now, the final examination is coming. As an excellent programmer,you is asked for help. The full mark is a, and it is need greater than or equal to pass subjects. Given the description of every subject, you should schedule the time of review to every subject in order to pass every sub Ject 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 a integer n (1<=n<=50), which is the number of subjects. Then n lines follow, each of the line have 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 would improve AI Scores,di (0<=di<=4): The Improving score s'll decrease di every reviewing hour. For example,when ai = ten, Di = 2, the first hour viewing would improve scores, and the second hour viewing would only IM Prove 8 scores.
Output
For each test case, the to output in one line. If He can pass all the subjects, please output an integer which was the highest total scores, otherwise please output a str ing "you are unlucky".
Sample Input
158 3 5 3158 1 5 3440 6 10 250 9 10 260 3 4 270 1 4 2442 6 10 250 9 10 254 3 4 270 1 4 2430 6 10 250 9 10 254 3 4 270 1 4 2
Sample Output
6563280274you is unlucky
HINT
Please noting:every subject ' full scores is 100. So when you get a result of one subject which are bigger than, you should regard the result as 100.
Problem Solving: Greed
First of all to ensure that all pass, according to the test time from small to large sorting, set a time to occupy the array to mark whether this time is occupied, and then on the subject of failure, from the end of the time from the forward, found an unused time, occupy the time, until passing.
Then with the priority queue, the priority to select the current can get the highest score of the first review, also from the time to go forward, encountered no occupation, directly occupied, jump out of the loop. If there are multiple maximum values, directly select the up-to-date ...
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN = +;4 structNode {5 ints,t,a,d;6 BOOL operator< (ConstNode &x)Const {7 if(A = = X.A)returnT <x.t;8 returnA <x.a;9 }Ten } COURSE[MAXN]; One intN; A BOOLUSED[MAXN]; -Priority_queue<node>Q; - BOOLcmpConstNode &x,ConstNode &y) { the returnx.t <y.t; - } - intMain () { - intret; + BOOLFlag; - while(~SCANF ("%d",&N)) { +memset (Used,false,sizeofused); AFlag =true; at while(!q.empty ()) Q.pop (); - for(inti = ret =0; 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(inti =0; I < n; ++i) { - for(intj = course[i].t; COURSE[I].A >0&& J >0&& Course[i].s < -; --j) { in if(!Used[j]) { -USED[J] =true; toCourse[i].s = min ( -, Course[i].s +course[i].a); +COURSE[I].A = Max (0, COURSE[I].A-course[i].d); - } the } * if(Course[i].s < -) { $Flag =false;Panax Notoginseng Break; -}ElseQ.push (Course[i]); the } + while(Flag &&!)Q.empty ()) { ANode now =q.top (); the Q.pop (); + if(NOW.S = = -|| NOW.A = =0) { -RET + =now.s; $ Continue; $ } - BOOLMark =false; - for(inti = now.t; i >0; --i) { the if(!Used[i]) { -Mark = Used[i] =true;WuyiNOW.S = min ( -, NOW.S +NOW.A); theNOW.A = Max (0, NOW.A-now.d); - Break; Wu } - } About if(Mark) Q.push (now); $ ElseRET + =now.s; - } - if(flag) printf ("%d\n", ret); - ElsePuts"You are unlucky"); A } + return 0; the}
View Code
Csuoj 1603 scheduling the final examination