ural 1915 Titan Ruins: Repeating Success and Failure
来源:互联网 发布:在淘宝买东西可靠吗 编辑:程序博客网 时间:2024/06/05 05:29
http://acm.timus.ru/problem.aspx?space=1&num=1915
题意:给你一堆数和一个堆栈,如果n>0,那么入栈,如果等于0,那么复制一下当前的堆栈,如果等于-1,输出栈顶元素。
/*这题最容易出现的就是数组越界,为了不越界,1数组开的足够大;2在数组越界之前ac 选择方法2来解决问题 因为n的最大值是10e-6,所以说当有10^3个在栈内,再来一个0,进行复制,这时剩下的操作数只有10^3个,那么我们这时就不用再复制了,因为就算是10^3个-1,我们堆栈内的数也足够输出*/#include<stdio.h>__int64 a[3000000];int top;int st[2000000]; int main(){ int n; while(~scanf("%d",&n)) { int i,zero,k,j; int flag=0; top=zero=0; for(k=1;k<=n;k++) { __int64 x; scanf("%I64d",&x); if(x>0) { a[top++]=x; } if(x==0) { if(flag) continue; i=top; for(j=0;j<i;j++) { a[top++]=a[j]; } if(top>=n-1)//如果发现堆栈总数已经达到了操作数,就不用再复制了 flag=1; //st[zero++]=top-1; } if(x==-1){printf("%I64d\n",a[--top]);} } } return 0;}
0 0
- ural 1915 Titan Ruins: Repeating Success and Failure
- URAL1915_Titan Ruins: Repeating Success and Failure_复杂度分析、机智
- URAL 1915 Titan Ruins: Reconstruction of Bygones(思路)
- URAL 1915 Titan Ruins: Reconstruction of Bygones (栈)
- ural 1917. Titan Ruins: Deadly Accuracy(Titan Ruins系列)
- ural 1915. Titan Ruins: Reconstruction of Bygones
- Ural 1910. Titan Ruins: Hidden Entrance
- URAL:1917 Titan Ruins: Deadly Accuracy
- URAL - 1917 Titan Ruins: Deadly Accuracy(水题)
- Ural 1910. Titan Ruins: Hidden Entrance
- URAL 1910. Titan Ruins: Hidden Entrance
- URAL 1910 Titan Ruins: Hidden Entrance
- URAL 1910. Titan Ruins: Hidden Entrance
- UVA 12647 Balloon (线段树) URAL 1915Titan Ruins: Reconstruction of Bygones (暴力,树状数组)
- ural 1910. Titan Ruins: Hidden Entrance(Titan Ruins系列题目)
- URAL 1910 Titan Ruins: Hidden Entrance 题解与翻译
- URAL - 1920 Titan Ruins: the Infinite Power of Magic(乱搞)
- URAL 1920 Titan Ruins: the Infinite Power of Magic
- CStatic如何影响WM_MOUSEWHEEL事件
- struts tiles
- [Leetcode] Rotate Matrix
- ZOJ 1074 To the Max (DP)
- linux yuan good
- ural 1915 Titan Ruins: Repeating Success and Failure
- 某词典软件取词问题
- OpenGL项目出现错误:error LNK2019: unresolved external symbol _gluErrorString@4
- HTTP的KeepAlive是开启还是关闭?
- 查看操作系统上文件系统块大小
- Mac OS使用技巧之三:发射无线网络信号的方法
- apt-get update apt-get upgrade
- 人生是个千疮百孔的鸡蛋
- hdoj 2045 LELE的RPG难题 解题报告(简单递推)