forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1363(AC).cpp
68 lines (61 loc) · 899 Bytes
/
POJ1363(AC).cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <stack>
using namespace std;
int b[1100];
int n;
int main()
{
int i, j;
bool terminate;
bool success;
stack<int> st;
while(true){
scanf("%d", &n);
if(0 == n){
break;
}
terminate = false;
while(!terminate){
for(i = 1; i <= n; ++i){
scanf("%d", &b[i]);
if(1 == i && 0 == b[i]){
terminate = true;
break;
}
}
if(terminate){
break;
}
while(!st.empty()){
st.pop();
}
success = true;
i = 1;
j = 1;
while(j <= n){
if(i == b[j]){
++i;
++j;
}else if(!st.empty() && st.top() == b[j]){
st.pop();
++j;
}else if(i <= n){
st.push(i);
++i;
}else{
success = false;
break;
}
}
if(success){
printf("Yes\n");
}else{
printf("No\n");
}
}
printf("\n");
}
return 0;
}