HDU 1509 Windows Message Queue

来源:互联网 发布:linux安装hadoop集群 编辑:程序博客网 时间:2024/06/03 22:46

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509

题目很容易理解,不说题意了。

这就是一道很裸的优先队列模板题。

下面是AC代码:

#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>#include<sstream>#include<vector>#include<map>#include<stack>#include<list>#include<set>#include<queue>#define LL long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1 | 1using namespace std;const int maxn=1005,maxe=100005,inf=1<<29;int n,m;struct node{    string message;    int s,v,id;    friend bool operator < (node a,node b)    {        if(a.v!=b.v) return a.v>b.v;        return a.id>b.id;    }};int main(){    string op,message;    int a,b,cnt=1;    priority_queue<node>q;    while(cin>>op)    {        if(op=="PUT")        {            cin>>message>>a>>b;            node t;            t.message=message,t.s=a,t.v=b,t.id=cnt++;            q.push(t);        }        else        {            if(q.size()==0) cout<<"EMPTY QUEUE!"<<endl;            else cout<<q.top().message<<" "<<q.top().s<<endl,q.pop();        }    }    return 0;}


0 0
原创粉丝点击