#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; }
时间: 2024-10-10 05:28:02