POJ2051 Argus

老是交错语言..

比扔石头还简单一点的优先队列

#include<cstdio>
#include<queue>
using namespace std;
struct node
{
    int id;
    int po;
    int le;
    bool operator<(const node &a) const
    {
        if (po==a.po) return id>a.id;
        else return po>a.po;
    }
};
int main()
{
    int k,i;
    char s[20];
    struct node a;
    priority_queue<node>q;
    while (scanf("%s",s)&&s[0]!='#')
    {
        scanf("%d%d",&a.id,&a.le);
        a.po=a.le;
        q.push(a);
    }
    scanf("%d",&k);
    while (k--)
    {
        a=q.top();
        q.pop();
        printf("%d\n",a.id);
        a.po+=a.le;
        q.push(a);
    }
}

猜你喜欢

转载自blog.csdn.net/parkerljc/article/details/79352017
今日推荐