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
Test instructions: n course, each course does not review can get S points, this course in T time exam, the first review can increase a points, every one more review of income reduction D, ask the final can pass, the general pass the biggest score when how much
Idea: Greedy, first we have to make a general pass, and then on this basis, continuous accumulation can increase the number of points, this situation using priority queue implementation
<pre name= "code" class= "CPP" > #include <iostream> #include <stdio.h> #include <string.h> # Include <stack> #include <queue> #include <map> #include <set> #include <vector> #include & Lt;math.h> #include <algorithm> using namespace std; #define LS 2*i #define RS 2*i+1 #define UP (i,x,y) for (i=x;i<=y;i++) #define OFF (i,x,y) for (i=x;i>=y;i--) #define Me M (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define LL long Long const double PI = ACOs (-1.0); #define LEN 200005 #define MOD 19999997 const int INF = 0X3F3F3F3F; #define EXP 1e-8 struct Node {int s,t,a,d; friend bool operator< (node A,node b) {return a.a<b.a; } int Check () {if (100-s>a) return A; else return 100-s; }} stu[55]; int n,hsh[750]; int main () {int i,j,k,flag; W ((~SCANF ("%d", &n)) {mem (hsh,1); flag = 1; Up (i,0,n-1) {scanf ("%d%d%d%D ", &STU[I].S,&STU[I].T,&STU[I].A,&STU[I].D); int tem = STU[I].T; W ((tem>0&&stu[i].s<60&&stu[i].a>0)) {if (Hsh[tem]) { Stu[i].s+=stu[i].check (); STU[I].A-=STU[I].D; hsh[tem]=0; } tem--; }} down (i,720,1) {if (Hsh[i]) {k =-1; Up (j,0,n-1) {if (stu[j].t>=i && (k==-1| | Stu[j].check () >stu[k].check ())) k = j; } if (K!=-1 && stu[k].a>0) {Stu[k].s+=stu[k].check (); STU[K].A-=STU[K].D; }}} int ans = 0; Up (i,0,n-1) {if (stu[i].s>=60) Ans+=stu[i].s; else {flag = 0; Break }} if (flag) printf ("%d\n", ans); else printf ("You are unlucky\n"); } return 0; }
Csu1603:scheduling The final examination (greedy)