现在的位置: 首页 > 综合 > 正文

hdu 1873 看病要排队

2018年12月30日 ⁄ 综合 ⁄ 共 531字 ⁄ 字号 评论关闭

优先队列简单题

 

 

#include <iostream>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
struct node
{
    int n;
    int i;
    friend bool operator < (node a, node b)
    {
        if(a.n==b.n)
             return a.i>b.i;
         else
             return a.n<b.n;
    }
};
int main()
{
    int n,A,B;
    node t;
    int k;
    char s[4];
    while(scanf("%d",&n)!=EOF)
    {
        k=1;
        priority_queue<node> Q[4];
        while(n--)
        {
           scanf("%s",s);
           if(s[0]=='I')
           {
               scanf("%d%d",&A,&B);
               t.n=B;
               t.i=k++;
               Q[A].push(t);
           }
           else
           {
               scanf("%d",&A);
               if(!Q[A].empty())
               {
                   t=Q[A].top();
                   Q[A].pop();
                   printf("%d\n",t.i);
               }
               else
               {
                   printf("EMPTY\n");
               }
           }
        }
    }
    return 0;
}

 

抱歉!评论已关闭.