UVA 514

#include<iostream>
#include<string>
#include<string.h>
#include<stack>
#include<stdio.h>
using namespace std;
int main(){
    int n,mm=0;
    int a[1010];
    while(cin>>n){
        if(n==0) break;
        while(true){
        stack<int> st;
        mm=0;
       memset(a,0,sizeof(a));
         for(int i=1;i<=n;i++){
            cin>>a[i];
          if(a[1]==0) {
            mm=-1;
            break;
            }
          }
          if(mm==-1) break;
       int A=1,B=1;
       int flag=1;
       while(B<=n){
        if(A==a[B]){A++;B++;}
        else if(!st.empty()&&st.top()==a[B]){B++;st.pop();}   //站->B
        else if(A<=n) {st.push(A);A++;}
        else {flag=0;break;}
       }
       if(flag==1)
        cout<<"Yes"<<endl;
       else
        cout<<"No"<<endl;
        }
        cout<<endl;
    }
    return 0;
}

 

posted @ 2016-01-30 14:40  咸咸的告别  阅读(203)  评论(0编辑  收藏  举报