优先队列模板题,菜鸡写的高手勿喷

http://acm.hdu.edu.cn/showproblem.php?pid=1873
这里附上题意链接:
题目大致意思就是按照病人的优先级排序,优先级相同就按照时间早晚排序,早的在前:
在此直接附上AC代码
#include
#include
#include
using namespace std;
struct node{
int x,id;
bool operator < (const node & rhs) const{
if(x == rhs.x)
{
return id > rhs.id;
}
else return x < rhs.x;
}
};
int main()
{
priority_queueq1,q2,q3;
//map<int,int>D;
int t;
while(cin >> t){
while(!q1.empty()) q1.pop();
while(!q2.empty()) q2.pop();
while(!q3.empty()) q3.pop();
int cnt = 1;
while(t–)
{
string s;
int A,B;
cin >> s;
if(s == “IN”)
{
node Q;
cin >> A >> B;
if(A == 1)
{
Q.x = B;
Q.id = cnt;
q1.push(Q);
cnt++;
}
else if(A == 2)
{
Q.x = B;
Q.id = cnt;
q2.push(Q);
cnt++;
}
else if(A == 3)
{
Q.x = B;
Q.id = cnt;
q3.push(Q);
cnt++;
}
}
else if(s == “OUT”)
{
cin >> A;
if(A == 1)
{
if(q1.empty())
{
cout << “EMPTY” <<endl;
}
else
{
cout << q1.top().id<< endl;
q1.pop();
}
}
else if(A == 2)
{
if(q2.empty())
{
cout << “EMPTY” <<endl;
}
else
{
cout << q2.top().id<< endl;
q2.pop();
}
}
else if(A == 3)
{
if(q3.empty())
{
cout << “EMPTY” <<endl;
}
else
{
cout << q3.top().id<< endl;
q3.pop();
}
}
}
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值