继续迷茫的优先队列........

2017-04-01  本文已影响0人  与卿__歌

HDU 1875

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct node
{
    int pri;
    int num;
    friend bool operator<(node n1,node n2)
    {
        if(n1.pri==n2.pri)
        return n2.num<n1.num;
        else
        return n1.pri<n2.pri;
    }
};
int  main()
{
    int n;
    node now;
    int a,b;
    char s[5];
    while(scanf("%d",&n)!=EOF)
    {
        int tot=0;
        priority_queue<node>q[4];
        while(n--)
        {
            scanf("%s",s);
            if(s[0]=='O')
            {
                scanf("%d",&a);
                if(q[a].empty())
                printf("EMPTY\n");
                else
                {
                    now=q[a].top();
                    q[a].pop();
                    printf("%d\n",now.num); 
                }
                
            }
            else
            {
                scanf("%d%d",&a,&b);
                now.num=++tot;
                now.pri=b;
                q[a].push(now);
                
            }
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读