求助屎山代码
查看原帖
求助屎山代码
544281
Qemu安卓楼主2023/11/3 21:16

RT



#include <bits/stdc++.h>

using namespace std;

#define MAXN 100000000

int nowtime = 0;
struct program
{
    int pid;
    int start;
    int time;
    int w;
} task[MAXN];

struct cmp
{
    bool operator()(const program &a, const program &b) const
    {
        if (a.pid == b.pid)
        {
            return a.time > b.time;
        }
        return a.start > b.start;
    }
};

priority_queue<program, vector<program>, cmp> tasks;

int main()
{
    int cnt = 1;
    while (cin >> task[cnt].pid >> task[cnt].start >> task[cnt].time >> task[cnt].w)
    {
        cnt++;
    }
    nowtime = tasks.top().start;
    while (!tasks.empty())
    {
        program data;
        program nxtdata;
        data = tasks.top();
        tasks.pop();
        nxtdata = tasks.top();
        nowtime += min(nxtdata.time - data.time, data.w);
        data.w -= nxtdata.time - data.time;
        if (data.w > 0)
        {
            data.start = nowtime;
            tasks.push(data);
        }
        else
        {
            cout << data.pid << " " << nowtime << endl;
        }
    }
}
2023/11/3 21:16
加载中...