30pts求调
查看原帖
30pts求调
983841
Pluto_Dream_Sky楼主2025/7/3 09:42
#include<bits/stdc++.h>
#define endl '\n'
#define prque priority_queue
#define int long long
using namespace std;
const int N=15005;
struct task{
    int o;//进程号
    int a;//到达时间
    int t;//运行时间
    int pr;//优先级 
};
bool operator < (task a,task b){
	if(a.pr!=b.pr) return a.pr<b.pr;
	else return a.a>b.a;
}
int o,a,t,p,ti;
prque<task> q;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    task x;
	while(cin>>x.o>>x.a>>x.t>>x.pr){
        while(q.size() && ti+q.top().t<x.a){//队首任务能在新任务到达之前完成
            task z=q.top();q.pop();
            ti+=z.t;//时间更新为执行完队首任务后的时间
            cout<<z.o<<' '<<ti<<endl;
        }
        if(q.size()){//如果有,处理终止在最新进程到达时正在处理的任务
            task z=q.top();q.pop();//这时的z是需要中止的任务
            z.t-=x.a-ti;//z仍需执行部分花费的时间是在新进程x到来之前所执行的时间
            q.push(z);
        }
		q.push(x);
        ti=x.a;
	}
    while(q.size()){//不要忘记最后处理还在队伍里等待的任务
            task z=q.top();q.pop();
            ti+=z.t;//时间更新为执行完队首任务后的时间
            cout<<z.o<<' '<<ti<<endl;
        }
	return 0;
}
2025/7/3 09:42
加载中...