码迷,mamicode.com
首页 > 其他好文 > 详细

LA 3135 Argus (优先队列)

时间:2015-01-29 12:32:16      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

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 (优先队列)

标签:

原文地址:http://www.cnblogs.com/sola1994/p/4259285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!