一道模拟题 题意待会解答:
#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;
}