现在的位置: 首页 > 综合 > 正文

hdu1873

2013年10月19日 ⁄ 综合 ⁄ 共 654字 ⁄ 字号 评论关闭

/*
分析:
    优先队列水题。
    注意优先队列要定义在大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;
}

抱歉!评论已关闭.