HDU1873看病要排队(STL优先队列)

解题思路:根据题意维护三个优先队列。优先队列的重载符operator的知识有缺漏!!!

AC代码如下:

#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

struct node
{
	int number,quan;
	friend bool operator <(node a,node b)
	{
		if(a.quan==b.quan)
			return a.number>b.number;
		else
			return a.quan<b.quan;
	}
}human;

priority_queue<node> A,B,C;

int main()
{
	int i,a,b,n,cnt;
	char s[100];
	while(~scanf("%d",&n))
	{
		while(!A.empty()) A.pop();
		while(!B.empty()) B.pop();
		while(!C.empty()) C.pop();
		for(i=cnt=1;i<=n;i++)
		{
			scanf("%s",s);
			if(strcmp(s,"IN")==0)
			{
				scanf("%d%d",&a,&b);
				human.number=cnt++;
				human.quan=b;
				if(a==1)
					A.push(human);
				else if(a==2)
					B.push(human);
				else
					C.push(human);
			}
			else
			{
				scanf("%d",&a);
				if(a==1 && !A.empty())
				{
					printf("%d\n",A.top().number);
					A.pop();
				}
				else if(a==2 && !B.empty())
				{
					printf("%d\n",B.top().number);
					B.pop();
				}
				else if(a==3 && !C.empty())
				{
					printf("%d\n",C.top().number);
					C.pop();
				}
				else
				{
					printf("EMPTY\n");
				}
			}
		}
	}
	return 0;
}

全部评论

相关推荐

06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
06-18 16:45
门头沟学院 Java
玩脱了,吊着两家结果两家都不要鼠鼠了,我真想给自己两巴掌。
凉风落木楚山秋:当作是你把这两家公司从地球开除了就行了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务