题目链接:可交题的传送门 记得刚入门的时候问过学长可不可以自己定义一个优先队列,不过学长没搭理我。。。
代码:
<span style="font-size:14px;">#include <bits/stdc++.h>
using namespace std;
struct node//注意优先队列里的比较函数,跟正常的正好相反。
{
int Qnum,Period,Time;
bool operator < (const node &t)const{
return Time>t.Time||(Time==t.Time&&Qnum>t.Qnum);
}
}a;
int main()
{
priority_queue<node> pq;
char s[20];
while(~scanf("%s",s)&&s[0]!='#')
{
scanf("%d%d",&a.Qnum,&a.Period);
a.Time=a.Period;
pq.push(a);
}
int k;
scanf("%d",&k);
while(k--)
{
a=pq.top();
pq.pop();
printf("%d\n",a.Qnum);
a.Time+=a.Period;
pq.push(a);
}
return 0;
}
</span>