专栏文章
插松枝
个人记录参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @miqaou6w
- 此快照首次捕获于
- 2025/12/04 01:42 3 个月前
- 此快照最后确认于
- 2025/12/04 01:42 3 个月前
CPP
/*
1.松枝满了
下一枝
2.松枝没满
1.小盒子不空且满足要求
插上
2.推送器不空
1.满足要求
插上
2.不满足
1.盒子不满
丢入盒子
2.盒子满了
下一枝
1.如果插过了
cnt++记录(帮助判断松枝有没有满)
*/
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
stack<int> e;
queue<int> q;
int main()
{
// ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>m>>k;
while(n--)
{
int x;
cin>>x;
q.push(x);
}
while(!q.empty()||!e.empty())
{
int cnt=0,st=1e9*2;
while(1)
{
if(cnt>=k)
{
break;
}
int flag=0;
if(!e.empty()&&e.top()<=st)
{
cout<<e.top()<<' ';
st=e.top();
e.pop();
flag=1;
}
else if(!q.empty())
{
while(!q.empty())
{
if(q.front()<=st)
{
cout<<q.front()<<' ';
st=q.front();
q.pop();
flag=1;
break;
}
if(e.size()>=m)
{
break;
}
e.push(q.front());
q.pop();
}
}
if(flag)
{
cnt++;
}
else break;
}
cout<<'\n';
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...