Problem Description
Problem Analysis
The idea is the same as that problem above
[HDU][1022]Train Problem I](http://blog.csdn.net/u011493189/article/details/50805953)
more or less
This one only needs to determine whether the pop sequence is possible
and does not require printing the process
so irrelevant variables such as the flag array are omitted
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
| #include<stdio.h>
#include<stack>
using namespace std;
int main() {
int n;
bool flag=false;
while(scanf("%d",&n),n) {
if(flag)
printf("\n");
int a[1200];
while(scanf("%d",&a[1]),a[1]) {
stack<int>s;
for(int i=2; i<=n; i++)
scanf("%d",&a[i]);
int j=1;
for(int i=1; i<=n; i++) {
s.push(i);
while(!s.empty()&&s.top()==a[j]) {
s.pop();
j++;
}
}
if(j-1==n)
printf("Yes\n");
else
printf("No\n");
}
flag=true;
}
return 0;
}
|
Problem address: [POJ][1363]Rails](http://poj.org/problem?id=1363)