ZOJ 1012 Mainframe

一道模拟题  题意待会解答:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long LL;

#define INF 0x7fffffff
#define MOD 10000007
#define M 10005
#define N 105
#define WAIT 1
#define PAUSE 2
#define ON 3

struct Job {
    int state;
    int cpu, memory, time_arrive, time_line, reward, bonus, punish;
};

Job map[M];

int F, Cpu, Memory, L, Rest_cpu, Rest_memory, Rest_time, Ans;

int cmp(Job a,Job b)
{
    if(a.time_arrive != b.time_arrive) {
        return a.time_arrive < b.time_arrive;
    } else {
        return a.reward > b.reward;
    }
}

void deal(Job a)
{
    int temp = Rest_time + 1;

    Ans += a.reward;
    Rest_cpu -= a.cpu;
    Rest_memory -= a.memory;

    if(a.time_line < temp) {
        Ans -= a.punish * (temp - a.time_line);
    } else if(a.time_line > temp) {
        Ans += a.bonus * (a.time_line - temp);
    }
}


int main(int argc,char* argv[])
{
    int Cas = 1;

    while(cin>>F && F) {
        cin>>Cpu >>Memory >>L;

        for(int i = 0; i < L; i++) {
            cin>>map[i].cpu >>map[i].memory >>map[i].time_arrive >>map[i].time_line >>map[i].reward >>map[i].bonus >>map[i].punish;
            map[i].state = WAIT;
        }

        sort(map, map+L, cmp);
        Ans = 0;
        Rest_time = 0;


        while(Rest_time < F) {
            Rest_cpu = Cpu;
            Rest_memory = Memory;

            for(int i = 0; i < L; i++) {
                if(map[i].state == PAUSE) {
                    if(map[i].cpu <= Rest_cpu && map[i].memory <= Rest_memory) {
                        map[i].state = ON;
                        deal(map[i]);

                    }
                } else if(map[i].time_arrive == Rest_time) {
                    if(map[i].cpu <= Rest_cpu && map[i].memory <= Rest_memory) {
                        map[i].state = ON;
                        deal(map[i]);
                    } else {
                        map[i].state = PAUSE;
                    }
                }
            }

            Rest_time++;
        }

        for(int i = 0; i < L; i++)
            if(map[i].state != ON && map[i].time_line < F) {
                Ans -= map[i].punish * (F - map[i].time_line);
            }

        cout<<"Case "<<Cas++<<": "<<Ans<<endl<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值