csu 1603: Scheduling the final examination(贪心)

本文介绍了一种利用智能算法为大学学生优化期末考试复习时间分配的方法,旨在帮助学生在有限时间内最大化总成绩,确保通过所有科目并取得最高可能的分数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1603: Scheduling the final examination

Time Limit: 10 Sec   Memory Limit: 128 MB
Submit: 43   Solved: 12
[ 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 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

题意不再赘述

先让所有考试的分数都能到达60  然后选取当前a值最大的考试进行复习。。。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define REP(x, y) for(int x = 0; x < y; x++)
#define DWN(x, y) for(int x = y-1; x > -1; x--)
struct Exam
{
    int s,t,a,d;
    int add()
    {
        if(100-s>a) return a;
        else return 100-s;
    }
}ex[60];
 
int timer[750];
 
int main()
{
//    freopen("D.in", "r", stdin);
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int mx=-1;
        memset(timer,0,sizeof timer);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d%d",&ex[i].s,&ex[i].t,&ex[i].a,&ex[i].d);
            mx=max(mx,ex[i].t);
            int t=ex[i].t;
            while(t>0&&ex[i].s<60&&ex[i].a>0)
            {
                if(timer[t]==0)
                {
                    ex[i].s+=ex[i].add();
                    ex[i].a-=ex[i].d;
                    timer[t]=1;
                }
                t--;
            }
 
        }
        for(int i=720;i>0;i--)
        {
            if(!timer[i])
            {
                int m=-1;
                for(int j=0;j<n;j++)
                {
                    if(ex[j].t>=i&&(m==-1||ex[m].add()<ex[j].add()))
                        m=j;
                }
                if(m!=-1&&ex[m].a>0)
                {
                    ex[m].s+=ex[m].add();
                    ex[m].a-=ex[m].d;
                }
            }
        }
        int ans=0;
        int flag=1;
        for(int i=0;i<n;i++)
        {
            if(ex[i].s>=60)
                ans+=ex[i].s;
            else
            {
                flag=0; break;
            }
        }
        if(flag)
            printf("%d\n",ans);
        else puts("you are unlucky");
    }
    return 0;
}
 
 
/**************************************************************
    Problem: 1603
    User: youngkl
    Language: C++
    Result: Accepted
    Time:8 ms
    Memory:1488 kb
****************************************************************/






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值