难得的水题,但还是wa了一次,仔细点就行了,没什么好说的。
#include <cstdio>
using namespace std;
int s[1005], top, y[1005], x;
int main(){
int n;
while(~scanf("%d", &n)&&n){
while(true){
scanf("%d", &y[0]);
if(y[0] == 0) {printf("\n");break;}
for(int i=1;i<n;i++)
scanf("%d", &y[i]);
top = 0; x = 1;
int p = 0;
while(p < n){
if(y[p] == x){
p++;
x++;
}else if(y[p] < x){
if(s[--top] != y[p]){
printf("No\n");
break;
}
p++;
}else if(y[p] > x){
s[top++] = x++;
}
}
if(p == n)
printf("Yes\n");
}
}
return 0;
}