Problem Description
http://acm.hdu.edu.cn/showproblem.php?pid=1873
7 IN 1 1 IN 1 2 OUT 1 OUT 2 IN 2 1 OUT 2 OUT 1 2 IN 1 1 OUT 1
2 EMPTY 3 1 1
/**
*优先队列问题,自定义优先级
*/
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cstring>
#include<cmath>
using namespace std;
struct node{//自定义结构体中的优先级
int v, t ;//v表示优先级,t表示时间
//node (int a,int b):d(a),s(b){}
bool operator <(const node a) const
{
if (v!=a.v) return v<a.v;
else return t>a.t;
}
};
struct cmp{//第二种定义方式
bool operator ()(node a, node b)
{
if(a.v>b.v) return 1;
if(a.v==b.v&&a.t<b.t) return 1;
return 0; //结构体中,x小的优先级高
}
};
int main()
{
int n;
while(cin>>n){
priority_queue<node> pq[4];
int c=0;//记录编号
string pre; int a,b;
for(int i=1;i<=n;i++){
cin>>pre;
if(pre=="IN"){
cin>>a>>b;
node n;
n.v=b; n.t=++c;//注意计数
pq[a].push(n);
}
if(pre=="OUT"){
cin>>a;
if(!pq[a].empty()){
cout<<pq[a].top().t<<endl;
pq[a].pop();
}
else{
cout<<"EMPTY"<<endl;
}
}
}
}
return 0;
}原文地址:http://blog.csdn.net/fool_ran/article/details/42429069