STL
-
queue<类型>名称
-
方法
front():队首
back():队尾
pop():移除队首,不返回任何东西
push():写入队尾
empty():判空
不支持sort
-
常用于bfs
-
附一道队列小题
#include<bits/stdc++.h>
using namespace std;
int a[202020];
int main(){
int n,pt=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
queue<int>b;
int x[2],j=0;
long long ans=0;
for(int i=0;i<n-1;i++){
while(j<2){
if((!b.empty()&&a[pt]>b.front())||pt==n){
x[j++]=b.front();
b.pop();
}else{
x[j++]=a[pt++];
}
}
ans+=x[0]+x[1];
b.push(x[0]+x[1]);
j=0;
}
printf("%lld",ans);
return 0;
}