HDU 1873 진 료 는 줄 을 서 야 합 니 다(우선 대기 열)

제목:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32590
코드:
#include<stdio.h>
#include<queue>
#include<string.h>

using namespace std;

struct node
{
    int num;
    int a,b;
    friend bool operator <(node x,node y)
    {
        if(x.b==y.b)return x.num>y.num;
        else return x.b<y.b;
    }
};

int main()
{
    int t,g,aa,bb;
    node va,vb;
    while(~scanf("%d",&t))
    {
        int k=1;
        priority_queue<node>q[4];
        char str[10];
        while(t--)
        {
            scanf("%s",str);
            if(strcmp(str,"IN")==0)
            {
                scanf("%d%d",&va.a,&va.b);
                va.num=k++;
                q[va.a].push(va);
            }
            else
            {
                scanf("%d",&g);
                if(!q[g].empty())
                {
                    vb=q[g].top();
                    q[g].pop();
                    printf("%d
",vb.num); } else { printf("EMPTY
"); } } } } }

좋은 웹페이지 즐겨찾기