hdu 1873 优先队列

     

#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std;
struct node
{
    int level;
    int index;
    /*bool operator<(const node t)const
    {
        if(level!=t.level)
        return level<t.level;
        else
        return t.index<index;
    }*/
    friend bool operator<(node n1,node n2)//更容易接受的重载写法
    {
        if(n1.level==n2.level)
        return n2.index<n1.index;         //level相同时,index越小越优先
        else
        return n1.level<n2.level;        //level越大越优先
    }
};
int main()
{
    int n,i,k,x,y;
    char cmd[4];
    node temp;
    while(scanf("%d",&n)!=EOF)
    {
        priority_queue<node>p[4];//定义优先队列,默认初始化
        /*while(!A.empty())
        A.pop();
        //A.clear();不可用
        while(!B.empty())
        B.pop();
        while(!C.empty())
        C.pop();*/
        for(i=1,k=1;i<=n;i++)
        {
            scanf("%s",cmd);
            if(cmd[0]=='I')
            {
                scanf("%d %d",&x,&y);
                temp.level=y;
                temp.index=k++;
                p[x].push(temp);
                /*if(x==1)A.push(temp);
                else if(x==2)B.push(temp);
                else C.push(temp);*/
            }
            else
            {
                scanf("%d",&x);
                if(p[x].empty())printf("EMPTY\n");
                else
                {
                    temp = p[x].top();
                    p[x].pop();
                    printf("%d\n",temp.index);
                }
                /*if(x==1)
                {
                    if(A.empty())cout<<"EMPTY"<<endl;
                    else
                    {
                        temp=A.top();
                        A.pop();
                        cout<<temp.index<<endl;
                    }
                }
                else if(x==2)
                {
                    if(B.empty())cout<<"EMPTY"<<endl;
                    else
                    {
                        temp=B.top();
                        B.pop();
                        cout<<temp.index<<endl;
                    }
                }
                else
                {
                    if(C.empty())cout<<"EMPTY"<<endl;
                    else
                    {
                        temp=C.top();
                        C.pop();
                        cout<<temp.index<<endl;
                    }
                }*/
            }
        }
    }
    return 0;
}

      中文题,题意好理解。直接给出代码,此题居然不能一次就通过。

(pop()写成了top(),又没有语法错,又过的了题目上的测试例子,真心出错难找啊)

哎,这眼睛的度数是越来越深了啊,敲代码最受伤的就是眼呢!!!!

  

原文地址:https://www.cnblogs.com/XDJjy/p/2997191.html