2017.11.1模拟 queue

http://www.elijahqi.win/archives/1464

#include<cstdio>
#include<algorithm>
#define N 11000000
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=gc();}
    while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
    return x*f;
}
int n,a[N],first,last;
int main(){
    //freopen("queue.in","r",stdin);
    n=read();int first=10000000>>1,last=first-1;
    for (int i=1;i<=n;++i){
        int x=read();
        if (x>0) a[--first]=x;
        if (x==-1) if (a[first]) printf("%d\n",a[first++]);
        if (x==0){
            if (last-first+1>=n-i) continue;int last1=last;
            for (int j=first;j<=last1;++j) a[++last]=a[j];
        }
    }
    return 0;
}

按照题意模拟即可 注意剪枝 即当我要复制的队列大小超过我剩余询问数时直接跳过 不去管他即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值