大意就是让你编写一个称为argus的系统,这个系统支持一个register的命令: Register Q_num Period
该命令注册了一个触发器,它每Period秒就会残生一个编号为 Q_num的事件。你的任务就是模拟出前k个事件。如果多个事情同时发生,先处理Q_num小的事件。
优先队列的使用。
练习了用struct类自定义优先级。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
struct order
{
int qnum,period,time;
bool operator <(const order &a)const{
return time > a.time||(time==a.time&& qnum > a.qnum) ;
}
};
int main()
{
priority_queue<order> a;
char x[10];
while(scanf("%s",x),strcmp(x,"#"))
{
order temp;
scanf("%d%d",&temp.qnum,&temp.period);
temp.time=temp.period;
a.push(temp);
}
int k;
scanf("%d",&k);
while(k--)
{
order temp=a.top();
a.pop();
printf("%d\n",temp.qnum);
temp.time+=temp.period;
a.push(temp);
}
}