zoj 1259 Rails
来源:互联网 发布:js pdf在线阅读 编辑:程序博客网 时间:2024/05/21 09:16
/*这道题调了一个上午老是WA后来上poj才发现自己的思路完全错了考虑问题太过简单后来重写了两次,终于过了。。。 */#define LOCAL#include<iostream>#include<stack>using namespace std;#define N 1001int a[N];int main(){#ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);#endif int i,j,n; while(cin>>n&&n) { while(1) { for(i=0;i<n;i++) { cin>>a[i]; if(a[0]==0) goto out; } stack<int>s; j=0;i=1; while(1) // 这个处理过程想了好久。。。 { if(i==a[j]&&i<=n) {i++;j++;} else if(!s.empty()&&s.top()==a[j]) { s.pop(); j++; if(s.empty()&&j==n) { cout<<"Yes"<<endl; break; } } else if(i<=n) {s.push(i);i++;} else if(s.empty()&&j==n) { cout<<"Yes"<<endl; break; } else { cout<<"No"<<endl; break; } } // } out: cout<<endl; } return 0;}