1603:scheduling The final examination time limit: ten Sec Memory Limit: MB
Submit: Solved: 18
[Submit] [Status] [Web Board] 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.
Source refers to the blog of a great God, but slightly different http://blog.csdn.net/libin56842/article/details/45460823
One thing to note: A is not necessarily to increase the score by a score, should be the minimum value with the 100-s
The example I gave
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8#define fre (i, A, b) for (i = A; I <b; i++) #define FREE (i,b,a) for (i = b; I >= a;i--) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SSF (N) scanf ("%s", N) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d", &a, &b ) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF printf#define Bug pf ("hi\n") usin G namespace Std; #define INF 0x3f3f3f3f#define N 1005struct stud{int s,t,a,d; BOOL operator < (CONST stud B) Const {if (A==B.A) return t>b.t; Return a<b.a; } void Check () {a=min (a,100-s);}} F[n];int CMP (stud S,stud ss) {return S.T<SS.T;} int N;int Used[n];int ans;priority_queue<stud>q;void Solve () {int I,j;stud cur,next;ans=0;while (!q.empty ()) Q.pop (); Fre (i,0,n) {Q.push (f[i]); ANS+=F[I].S; while (!q.empty ()) {cur=q.top (); Q.pop (); if (cur.a<=0) continue;for (i=cur.t;i>=1;i--) if (!used[i]) break;if (i= =0) Continue;used[i]=1;ans+=cur.a;cur.s+=cur.a;cur.a-=cur.d;cur.a=max (0,CUR.A); Cur.check (); if (cur.a>0) Q.push (cur);} printf ("%d\n", ans);} int main () {int i,j;while (~SF (n)) {mem (used,0); Fre (i,0,n) {scanf ("%d%d%d%d", &F[I].S,&F[I].T,&F[I].A, &F[I].D); F[i].check (); }sort (f,f+n,cmp); int Flag=0;fre (i,0,n) {while (f[i].s<60) {if (f[i].a<=0) break; for (j=f[i].t;j>=1;j--) if (!used[j]) break;if (j==0) Break;used[j]=1;f[i].s+=f[i].a;f[i].a-=f[i].d;f[i].a=max (f[ i].a,0); F[i].check (); } if (f[i].s<60) flag=1; if (flag) break;} if (flag) {printf ("You are unlucky\n"); continue;} Solve ();} return 0;} /*280 1 15 1590 1 20 10185*/
CSU 1603 scheduling The final examination (greedy)