CSU 1603 Scheduling the final examination(贪心)

1603: Scheduling the final examinationTime Limit: 10 SecMemory Limit: 128 MBSubmit: 58Solved: 18[Submit][Status][Web Board]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 Input158 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 2Sample Output6563280274you are unluckyHINT

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.

Source

参考了一位大神的博客,不过略有不同

需要注意的一点:a不一定是使分数提高a分数,应该与100-s取最小值

我给出的样例

#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 pfprintf#define bugpf("Hi\n")using 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(贪心)

相关文章:

你感兴趣的文章:

标签云: