题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1873
运用优先队列写就行了
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
#define N 2100
using namespace std; struct node
{
int ID,B;
friend bool operator < (node n1,node n2)
{
if(n1.B != n2.B)
return n1.B < n2.B;
return n1.ID >n2.ID;
}
}; int main()
{
int n,i,m,x,y;
char str[],ch,s[N];
node a,z; while(scanf("%d",&n)!=EOF)
{
priority_queue<node>q[];//如果定义在上面要记得清零;
m=;
for(i=;i<=n;i++)
{
scanf("%s",str);
scanf("%c",&ch);
if(strcmp(str,"IN")==)
{
m++;
gets(s);
sscanf(s,"%d %d",&x,&y);
a.ID=m;
a.B=y; q[x].push(a); }
else
{
scanf("%d",&x);
if(!q[x].empty())
{
z=q[x].top();
printf("%d\n",z.ID);
q[x].pop();
}
else
printf("EMPTY\n");
}
}
}
return ;
}