Posted on 2008-06-01 16:52
superman 阅读(401)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1259 C++ 00:00.10 848K */
2 #include <stack>
3 #include <iostream>
4
5 using namespace std;
6
7 int main()
8 {
9 int n, s[1001];
10 while(scanf("%d", &n) && n)
11 while(true)
12 {
13 scanf("%d", s + 1);
14 if(s[1] == 0)
15 {
16 cout << endl; break;
17 }
18 for(int i = 2; i <= n; i++)
19 scanf("%d", s + i);
20
21 stack <int> st;
22
23 int lp = 1, rp = 1;
24 while(lp <= n)
25 {
26 if(rp <= n && s[lp] == rp)
27 {
28 lp++, rp++; continue;
29 }
30 if(st.empty())
31 {
32 if(rp < n)
33 st.push(rp++);
34 else
35 {
36 cout << "No"; goto over;
37 }
38 }
39 else
40 {
41 if(s[lp] == st.top())
42 {
43 lp++; st.pop();
44 }
45 else
46 {
47 if(rp < n)
48 st.push(rp++);
49 else
50 {
51 cout << "No"; goto over;
52 }
53 }
54 }
55 }
56 cout << "Yes";
57 over:
58 cout << endl;
59 }
60
61 return 0;
62 }
63