hdu1873

/*
分析:
    优先队列水题。
    注意优先队列要定义在大while里面,等效于每次都
初始化为空。


                                           2012-09-16
*/






#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"queue"
using namespace std;
int tot;
struct node
{
	int pri;
	int num;
	friend bool operator<(node n1,node n2)
	{
		if(n1.pri==n2.pri)	return n2.num<n1.num;
		else				return n1.pri<n2.pri;
	}
};
int main()
{
	int n;
	node now;
	int a,b;
	char str[20];
	while(scanf("%d",&n)!=-1)
	{
		priority_queue<node>q[4];
		tot=0;
		while(n--)
		{
			scanf("%s",str);
			if(strcmp(str,"OUT")==0)
			{
				scanf("%d",&a);
				if(q[a].empty())	printf("EMPTY\n");
				else
				{
					now=q[a].top();
					q[a].pop();
					printf("%d\n",now.num);
				}
			}
			else if(strcmp(str,"IN")==0)
			{
				scanf("%d%d",&a,&b);
				now.num=++tot;
				now.pri=b;
				q[a].push(now);
			}
		}
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值