|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 |
#include<cstdio>#include<stack>using
namespace
std;const
int
MAXN=1000+10;int
n,target[MAXN];int
main(){ while(scanf("%d",&n)==1) { 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;} |
原文:http://www.cnblogs.com/firstsy0709/p/3614591.html