# include<cstdio># include<stack>using namespace std;const int MAXN = 1000+10;int n, target[MAXN];int main(void){while(scanf("%d", &n)!=EOF){ stack<int> s; int A=1, B=1; for(int i=1; i<=n; i++) scanf("%d", &target[i]); int ok =1; while(B<=n) { if(A==target[B]) //在A中找{ A++;B++; }else if(!s.empty()&&s.top()==target[B]) //A中找不到到C中找{ s.pop(); B++; }else if(A<=n) //都找不到就A中最前的车厢开进C{ s.push(A++);}else //找不到了,就是NO~{ ok=0; break;} } printf("%s\n", ok? "Yes":"No");} return 0;}
# include<stdio.h>const int MAXN = 1000+10;int n, target[MAXN];int main(void){while(scanf("%d", &n)!=EOF){ int stack[MAXN], top=0; int A=1, B=1; int ok=1; for(int i=1; i<=n;i++) scanf("%d", &target[i]); while(B<=n) { if(A==target[B]){ A++;B++;}else if(top&&stack[top]==target[B]){ top--; B++;}else if(A<=n){ stack[++top] = A++;}else{ ok=0; break;} } printf("%s\n", ok?"Yes":"No");} return 0;}