首页 > 代码库 > hdu 1873看病要排队(优先队列)

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

# 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看病要排队(优先队列)