【栈】例题6-2 UVa 514
2017-04-30 20:44
246 查看
/* 算法竞赛入门 LRJ 例题6-2(UVa 514)Rails */ #include<iostream> #include<cstdio> #include<cstring> #include<stack> #include<map> #include<queue> #include<cmath> #include<algorithm> #include<deque> typedef long long LL; using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") const int INF=0x3f3f3f3f; const int N = 10010; int a ; stack<int> Q; int main() { int n; while(~scanf("%d",&n), n) { while(~scanf("%d",&a[1])) { if(a[1] == 0) break; for(int i = 2; i <= n; i++) scanf("%d",&a[i]); int in = 1,out = 1; while(out <= n) { if(in == a[out]) in++,out++; else if(!Q.empty() && Q.top() == a[out]) Q.pop(),out++; else if(in < n) Q.push(in++); else break; } if(out != n+1) printf("No\n"); else printf("Yes\n"); } puts(""); } return 0; }
相关文章推荐
- 经典第六章 例题 6-2 UVA 514 Rails(栈的基础应用)
- 紫书例题6-2 UVa 514 ( 栈
- 算法竞赛入门经典第六章例题6-2 Rails UVA - 514
- 【例题 6-2 UVA - 514】Rails
- 例题6-2 铁轨(Rails, ACM/ICPC CERC 1997, UVa 514)
- 例题6-2 UVA 514 - Rails (铁轨)
- 章三例题2——UVA 10082
- 章三例题4——UVA 340 Master -Mind Hints
- 章三例题6——UVA 1584
- 算法竞赛入门经典训练指南 例题1-15 网络 Network UVALive 3902
- 例题3_4 猜数字游戏的提示(UVa340)
- UVA-514 Rails
- 紫书章七 例题2 UVA 11059 Maximum Product
- 【算法竞赛入门经典】6.5[图的BFS] 例题6-20 UVa1599 (2)
- 例题 5-5 集合栈计算机 Uva 12096
- 紫书动规 例题9-3 UVA - 1347 Tour dp
- 【紫书】例题3-6 环状序列(Circular Sequence, ACM/ICPC Seoul 2004, UVa1584)
- 例题8-2 联合国大楼 UVa 1605
- uva 514
- 紫书章七例题八 Fill uva 10603