您的位置:首页 > 其它

【栈】例题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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: