zoukankan      html  css  js  c++  java
  • 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
    ",r.QNum);
            r.Time +=r.Period;
            pq.push(r);
        }
        return 0;
    }
  • 相关阅读:
    外星人(alien)
    6. 第 6 章 函数
    5. 第 5 章 循环
    4. 第 4 章 条件选择
    3. 第 3 章 表达式和交互
    2. 第 2 章 C++简介
    1. 第 1 章 计算机和编程简介
    24. 蛇形填数
    23. 开灯问题
    12. aabb
  • 原文地址:https://www.cnblogs.com/sola1994/p/4259285.html
Copyright © 2011-2022 走看看