数据结构基础题
思路见码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
using namespace std;
#define LL long long
const int maxn=1010;
int n,target[maxn];
int main(){
while(scanf("%d",&n)){
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++;B++;}
else if(!s.empty()&&s.top()==target[B]) {s.pop();B++;}
else if(A<n) {s.push(A);A++;}
else {ok=0;break;}
}
printf("%s\n",ok?"Yes":"No");
}
return 0;
}