URAL 1915 Titan Ruins: Reconstruction of Bygones(思路)

搞这个题差不多是从比赛开始到结束。

从自信慢慢的看题一直到wrong到死。

这个题目可以说成是思路题,以为我们只要明白一点,这道题就成了纯暴力的水题,

那就是当操作数不足栈中数字数目的时候,我们就没有必要复制了。

注意数组要开足,如果是一路复制的话,2^20就可以到10^6次方级了,在cur<n的情况下,cur的范围是有可能超10^6的,所以,我们至少要开到2*10^6大小。

代码如下:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define M 1000005

using namespace std;

int st[2*M];

int main ()
{
    int n, x, cur;
    while(~scanf("%d",&n))
    {
        cur = 0;
        while(n--)
        {
            scanf("%d",&x);
            if(x==0)
            {
                if(cur<n)
                {
                    for(int i = 0; i < cur; ++i)
                        st[cur+i] = st[i];
                    cur += cur;
                }
            }
            else if(x==-1)
            {
                cur-=1;
                printf("%d\n",st[cur]);
            }
            else
            {
                st[cur] = x;
                ++cur;
            }
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值