您的位置:首页 > 其它

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

2016-02-16 18:16 369 查看
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32590

代码:

#include<stdio.h>
#include<queue>
#include<string.h>

using namespace std;

struct node
{
int num;
int a,b;
friend bool operator <(node x,node y)
{
if(x.b==y.b)return x.num>y.num;
else return x.b<y.b;
}
};

int main()
{
int t,g,aa,bb;
node va,vb;
while(~scanf("%d",&t))
{
int k=1;
priority_queue<node>q[4];
char str[10];
while(t--)
{
scanf("%s",str);
if(strcmp(str,"IN")==0)
{
scanf("%d%d",&va.a,&va.b);
va.num=k++;
q[va.a].push(va);
}
else
{
scanf("%d",&g);
if(!q[g].empty())
{
vb=q[g].top();
q[g].pop();
printf("%d\n",vb.num);
}
else
{
printf("EMPTY\n");
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: