时间:2025-10-23 21:21
人气:
作者:admin
此题是一道大模拟,主要根据任务优先级来计算最后执行此任务的时间,此时我们可以进行分类讨论:
我们需要用个变量 lati 来存总时间,因此本文中的上一个 "上一个未执行完任务的结束时间" 是指 lati + 上个任务的执行时间
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node{
ll id,be,ti,yx;
bool operator < (const node &a)const{
if(yx==a.yx) return be>a.be;
return yx<a.yx;
}
}a;
ll lati;
priority_queue<node> q;
int main(){
while(scanf("%lld%lld%lld%lld",&a.id,&a.be,&a.ti,&a.yx)!=EOF){
while(q.size()&&q.top().ti+lati<=a.be){
node b=q.top();
q.pop();
cout<<b.id<<" "<<lati+b.ti<<"\n";
lati+=b.ti;
}
if(q.size()){
node b=q.top();
q.pop();
b.ti-=a.be-lati;
q.push(b);
}
q.push(a);
lati=a.be;
}
while(q.size()){
node b=q.top();
q.pop();
lati+=b.ti;
cout<<b.id<<" "<<lati<<"\n";
}
return 0;
}
上一篇:轻量级图片信息解析程序