好久没写博客啦,最近ACM集训学到了深搜(DFS)和广搜(BFS),学之前先学学队列的用法,于是就发现了这道题!!!

这是一道简单的模板题,所以直接上AC代码!!!!
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <queue> //队列头文件
#include <vector> //动态数组头文件
#include <functional> //functional头文件
using namespace std;
// priority_queue 优先队列
// vector 动态数组
// greater 从大到小排序(less为从小到大排序)
priority_queue<int, vector<int>, greater<int> > pq; //创建优先队列
int main()
{
int n = 0;
cin >> n;
while (n--)
{
int op = 0; //定义操作类型
cin >> op;
if (op == 1) // op == 1时将x加入队列
{
int x = 0;
cin >> x;
pq.push(x); // 在pq队列队尾处插入一个元素n O(logn)
// 并排序
}
else if (op == 2) // op == 2时,输出队列中最小数
{
cout << pq.top() << endl; //访问队头元素 O(1)
}
else if (op == 3) // op == 3时,删除队列中最小的一个数
{
pq.pop(); // 弹出队头元素 O(logn)
}
}
return 0;
}如果有不清楚的地方欢迎来讨论!!!!!