CSU1603: Scheduling the final examination(贪心)

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.


Source


题意:N门课,每门课不复习能得到S分,这门课在T时间考试,第一次复习能增加A分,每多一次复习收益减少D,问最后能不能全科及格,全科及格最大的分数时多少

思路:贪心,首先我们要先使得全科及格,然后在这个基础上,不断的累加能够增加分数最多的情况,这种情况使用优先队列实现

<pre name="code" class="cpp">#include <iostream> 
#include <stdio.h> 
#include <string.h> 
#include <stack> 
#include <queue> 
#include <map> 
#include <set> 
#include <vector> 
#include <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 down(i,x,y) for(i=x;i>=y;i--) 
#define mem(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; 
} 

 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值