头文件#include
基本函数
和队列基本操作相同:
top 访问队头元素
empty 队列是否为空
size 返回队列内元素个数
push 插入元素到队尾 (并排序)
emplace 原地构造一个元素并插入队列
pop 弹出队头元素
swap 交换内容
例题1:看病要排队 HDU - 1873
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
struct sick {
int x;
int y;
friend bool operator < (sick n1 , sick n2){
if(n1.y == n2.y) return n1.x > n2.x;
return n1.y < n2.y;
}
};
int main(){
int n;
while(cin >> n){
priority_queue<sick> doc[4];
int id = 1;
sick temp;
for(int i = 0; i < n; i++ ){
string str;
int num1 , num2;
cin >> str ;
if(str == "IN") {
cin >> num1 >> num2;
temp.x = id;
temp.y = num2;
doc[num1].push(temp);
id++;
}
else {
cin >> num1;
if(!doc[num1].empty()){
cout << doc[num1].top().x << endl;
doc[num1].pop();
}
else cout << "EMPTY" << endl;
}
}
}
}