题意:Argus系统支持一个Register命令:Register Q_num Period
该命令注册了一个触发器,它每Period秒就会产生一次编号为Q_num的事件。你的任务是模拟出前k个事件。如果事件同时发生,先处理Q_num小的事件。
#include<cstdio>
#include<queue>
using namespace std;
struct node
{
int num,period,time;
}p;
bool operator < (node a,node b)
{
return a.time>b.time || (a.time==b.time && a.num>b.num);
}
int main()
{
int k;
char s[10];
priority_queue<node>q;
while(scanf("%s",s)!=EOF && s[0]!='#')
{
scanf("%d%d",&p.num,&p.period);
p.time=p.period;
q.push(p);
}
scanf("%d",&k);
while(k--)
{
p=q.top();q.pop();
printf("%d\n",p.num);
p.time+=p.period;
q.push(p);
}
return 0;
}