先把自己debug了四个小时的代码摆一下.....累了..回头再看哪错了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int main(){
int n,m,k;
cin>>n>>m>>k;//n为滑道上 m为盒子里放的最大数量 k为松枝能插几片叶子
queue<int>q;
vector<int> tree;
stack<int>box;
while(n--){
int x;
cin>>x;
q.push(x);
}
while(!q.empty()||!box.empty()){
tree.clear();
if(tree.empty()){
if(!box.empty()) {
int x=box.top();
box.pop();
tree.push_back(x);
}else{
int x=q.front();
q.pop();
tree.push_back(x);
}
// cout<<tree.back()<<endl;
}
while(!tree.empty()&&tree.size()<=k){//树 不空 不满
if(!box.empty()&&box.top()<=tree.back()){//如果盒子不空 并且盒顶的数比树顶的树小于等于
int x=box.top();
box.pop();
tree.push_back(x);//把盒顶的数拿给树
}else {
if(!q.empty()){//如果队列不空,盒子不满
int x=q.front();
if(box.size()!=m)q.pop();//把队列的数拿一个
if(x<=tree.back()) {//如果这个数比树顶的小或相等
tree.push_back(x);//给树顶
if(box.size()==m) q.pop();
// cout<<x<<endl;
}
else {
box.push(x);//不是的话 放盒子里
}
}
else {//如果队列空了,或者队列不空盒子满了
for(auto x : tree) cout<<x<<' ';
cout<<endl;
break;
}
}
}
// exit(0);
}
return 0;
}