UVa 514 铁轨

题意:

复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int num[1007];
    int kase = 0;
    while(scanf("%d", &n) != EOF && n != 0)
    {
        while(scanf("%d", &num[0]) && num[0] != 0){
            stack<int> s1;
            num[1] = num[0];
            for(int i = 2; i <= n; i++){
                scanf("%d", num+i);
            }
            int ok = 0;
            int A = 1, B = 1;
            while(B <= n){
                if(A == num[B]){A++; B++;}
                else if(!s1.empty() && s1.top() == num[B]){s1.pop(); B++;}
                else if(A <= n) s1.push(A++);
                else {ok =0; break;};
            }
            if(ok) printf("Yes\n");
            else printf("No\n");
        }
        printf("\n");
    }
}
复制代码

 

posted @   Neord  阅读(278)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示