# 題目

zerojudge c123. 00514 - Rails

# 解題思路

目前沒東西...

# 程式碼

#include<bits/stdc++.h>
using namespace std;
#define N 1005
int n,temp;
stack<int> stk;
bool test(stack<int> &_stk,int n){
    stack<int> tstk;
    while(!_stk.empty()){
        tstk.push(_stk.top());
        _stk.pop();
        while(!tstk.empty() && tstk.top()==n){
            tstk.pop();
            n--;
        }
    }
    if(n==0) return true;
    else return false;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    while(cin>>n){
        if(n==0) break;
        while(1){
            cin>>temp;
            if(temp==0) break;
            stk.push(temp);
            for(int i=1;i<n;i++){
                cin>>temp;
                stk.push(temp);
            }
            if(test(stk,n)) cout<<"Yes\n";
            else cout<<"No\n";
        }
        cout<<"\n";
    }
}
更新於 閱讀次數 次