首页 > 代码库 > LA 3135 Argus (优先队列)

LA 3135 Argus (优先队列)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1136

 

 

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespace std;struct Item{    int QNum,Period,Time;    /*bool operator < (const Item &a) const    {        return Time > a.Time ||(Time == a.Time &&QNum>a.QNum);    }*/    friend bool operator  < (Item a,Item b) {return a.Time>b.Time||(a.Time==b.Time&&a.QNum>b.QNum);}  //比较倾向第二种写法  对 > 来说 小的先出列};int main(){    priority_queue<Item> pq;    char s[20];    while(scanf("%s",s)&&s[0]!=#)    {        Item item;        scanf("%d%d",&item.QNum,&item.Period);        item.Time = item.Period;        pq.push(item);    }    int K;    scanf("%d",&K);    while(K--)    {        Item r=pq.top();        pq.pop();        printf("%d\n",r.QNum);        r.Time +=r.Period;        pq.push(r);    }    return 0;}

 

LA 3135 Argus (优先队列)