码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1873看病要排队(优先队列)

时间:2014-07-21 11:36:44      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:hdu 1873   namespace   struct   

# include <stdio.h>
# include <algorithm>
# include <queue>
using namespace std;
struct node
{
	int  y;
	int val;
	int num;
	friend bool operator<(node n1,node n2)
	{
		if(n1.val==n2.val)
			return n1.num>n2.num;//从小到大
		return n1.val<n2.val;//从大到小
	}
};
struct node temp;
int main()
{
	int n,i,a,b;
	int t;
	char s[5];
	priority_queue<node> A,B,C;
	while(~scanf("%d",&n))
	{
		t=0;
		while(!A.empty())
			A.pop();
		while(!B.empty())
			B.pop();
		while(!C.empty())
			C.pop();
		for(i=0;i<n;i++)
		{
			scanf("%s",s);
			if(strcmp(s,"IN")==0)
			{
				scanf("%d%d",&a,&b);
				if(a==1)
				{
					temp.val=b;
					temp.num=++t;
					A.push(temp);//A医生
				}
				else if(a==2)
				{
					temp.val=b;
					temp.num=++t;
					B.push(temp);//B医生
				}
				else
				{
					temp.val=b;
					temp.num=++t;
					C.push(temp);//C医生				
				}
			}
			else
			{
				scanf("%d",&a);
				if(a==1)
				{
					if(A.empty())
					{
						printf("EMPTY\n");
					    continue;
					}
					temp=A.top();
					A.pop();
					printf("%d\n",temp.num);
					
				}
				else if(a==2)
				{
					if(B.empty())
					{
						printf("EMPTY\n");
					   continue;
					}
					temp=B.top();
					B.pop();
						printf("%d\n",temp.num);
						}
				else
				{
					if(C.empty())
					{
						printf("EMPTY\n");
					    continue;
					}
					temp=C.top();
					C.pop();
					printf("%d\n",temp.num);
					
				}
			}
		}
	}
	return 0;
}

hdu 1873看病要排队(优先队列)

标签:hdu 1873   namespace   struct   

原文地址:http://blog.csdn.net/lp_opai/article/details/38010371

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!