原题链接
考察:模拟,贪心
思路:
??万恶的模拟+离线处理题.
??对于相邻的0之间的数字,最大的放在stack
里,其次在队列,最后在双端队列.
??要注意的是可能末尾没有0
Code
#include <iostream>
#include <cstring>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
using namespace std;
const int N = 100010;
int n,op,a[N];
string ans[N];
struct Node{
int id,val;
bool operator<(const Node& x){
return this->val<x.val;
}
}node[N];
void Myprintf(int cnt,int pos)
{
if(!cnt) {puts("0");return;}
sort(node+1,node+cnt+1);
if(cnt==1)
{
puts("pushStack");
if(!pos) puts("1 popStack");
return;
}
if(cnt==2)
{
printf("pushStack\npushQueue\n");
if(!pos) printf("2 popStack popQueue\n");
return;
}
ans[node[cnt].id] = "pushStack";
ans[node[cnt-1].id] = "pushQueue";
ans[node[cnt-2].id] = "pushFront";
for(int i=cnt-3;i>=1;i--) ans[node[i].id] = "pushBack";
for(int i=1;i<=cnt;i++) printf("%s\n",ans[i].c_str());
if(!pos) printf("3 popStack popQueue popFront\n");
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
int cnt = 0;
for(int i=1;i<=n;i++)
{
if(a[i])
{
cnt++;
node[cnt].id = cnt;
node[cnt].val = a[i];
}else{
Myprintf(cnt,a[i]);
cnt = 0;
}
}
if(cnt) Myprintf(cnt,1);
return 0;
}