优先队列基础

来源:互联网 发布:游戏辅助编程 编辑:程序博客网 时间:2024/06/01 21:46

HDU1873

题目链接

题解:裸题,注意队列要清空,记下优先队列模板;

Code:

#include <cstdio>#include <queue>using namespace std;struct p{    int no;    int level;    friend bool operator <(p a,p b)    {        if(a.level==b.level)return a.no>b.no;        return a.level<b.level;    }};priority_queue<struct p> xq[5];int main(){    int n,a,b;    char s[100];    while(scanf("%d",&n)!=EOF)    {        int k=0;        for(int i=1;i<=3;i++)        while(!xq[i].empty())xq[i].pop();//****        for(int i=1; i<=n; i++)        {            scanf(" %s %d",s,&a);            if(s[0]=='I')            {                scanf("%d",&b);                p x;                x.level=b;                x.no=(++k);                xq[a].push(x);            }            else if(s[0]=='O')            {                if(xq[a].empty())                {                    printf("EMPTY\n");                }                else                {                    printf("%d\n",(xq[a].top()).no);                    xq[a].pop();                }            }        }    }    return 0;}


0 0
原创粉丝点击