题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873
第一次写的优先队列题,准确来说不是写,是从网上找资料再从那里copy过来的。。。。。。。
不过还是要保存下来学习。。。。。
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct patient
{
int num;/*编号*/
int imp;/*重要度*/
}w[1001];
struct comp
{
bool operator()(patient &x,patient &y)/*结构体排序*/
{
if(x.imp<y.imp) return true;
if(x.imp==y.imp&&x.num>y.num) return true;
return false;
}
};
int main()
{
int n,i,a,b,count;
char str[101];
while(~scanf("%d",&n))
{
priority_queue<patient,vector<patient>,comp>doc[4];/*优先队列*/
count=1;
while(n--)
{
scanf("%s",str);
if(str[0]=='I')
{
scanf("%d %d",&a,&b);
w[count].num=count;
w[count].imp=b;
doc[a].push(w[count]);/*直接插入一个结构体....*/
count++;
}
else
{
scanf("%d",&a);
if(doc[a].empty())
{
printf("EMPTY\n");
}
else
{
printf("%d\n",doc[a].top().num);
doc[a].pop();
}
}
}
}
return 0;
}