POJ1363-Rails
http://poj.org/problem?id=1363
#include<cstdio> #include<stack> using namespace std; int a[1000]; int main(void) { int n; while(scanf("%d",&n),n) { int x,t; stack<int> q; while(scanf("%d",&x)&&x) { a[1]=x; for(int i=2;i<=n;i++) scanf("%d",&a[i]); int num=1; for(int i=1;i<=n;i++) { q.push(i); t=q.top(); while(t==a[num]&&num<=n) { num++; q.pop(); if(!q.empty()) t=q.top(); } } if(num>n) printf("Yes\n"); else printf("No\n"); } printf("\n"); } return 0; }