标签:ios algo ons printf ace node amp cst argus
用堆维护每个触发器的下一个事件,每次取出一个事件再把对应触发器的下一个事件加入堆即可
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iostream>
#include <string>
using namespace std;
struct QNode{
int time,num,Period;
bool operator < (const QNode &b) const{
return (time==b.time)?num>b.num:time>b.time;
}
};
priority_queue<QNode> q;
int main(){
string s;
while(cin>>s&&s=="Register"){
int num,pro;
scanf("%d %d",&num,&pro);
q.push((QNode){pro,num,pro});
}
int k;
scanf("%d",&k);
for(int i=1;i<=k;i++){
printf("%d\n",q.top().num);
QNode x=q.top();
q.pop();
q.push((QNode){x.time+x.Period,x.num,x.Period});
}
return 0;
}
标签:ios algo ons printf ace node amp cst argus
原文地址:https://www.cnblogs.com/dreagonm/p/10681641.html