01 queue队列
02 priority_queue优先队列
接下来介绍几种优先队列修改比较函数的方法
03 deque双端队列
04 例题讲解
https://www.lanqiao.cn/problems/1113/learning/?page=1&first_category_id=1&problem_id=1113
输入
5
IN xiaoming N
IN Adel V
IN laozhao N
OUT N
IN CLZ V
输出
Adel
CLZ
laozhao
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int main(){
string op,name,clase;
int n;
queue<string>quv,qun;
cin>>n;
for(int i=1;i<=n;i++){
cin>>op;
if(op=="IN"){
cin>>name>>clase;
if(clase=="V") quv.push(name);
else qun.push(name);
}
else{
cin>>clase;
if(clase=="V") quv.pop();
else qun.pop();
}
}
while(quv.size()){
cout<<quv.front()<<endl;
quv.pop();
}
while(qun.size()){
cout<<qun.front()<<endl;
qun.pop();
}
}
https://www.lanqiao.cn/problems/741/learning/?page=1&first_category_id=1&problem_id=741
#include<bits/stdc++.h>
using namespace std;
int n,x;
int main()
{
cin>>n;
int res=0;
priority_queue<int,vector<int>,greater<int>> q;
while(n--)
{
cin>>x;
q.push(x);
}
while(q.size()>1)
{
int a=q.top(); q.pop();
int b=q.top(); q.pop();
res+=a+b;
q.push(a+b);
}
cout<<res<<endl;
return 0;
}