import java.util.*;
// Sample Input
// 5
// 1 2 3 4 5
// 5 4 1 2 3
// 0
// 6
// 6 5 4 3 2 1
// 0
// 0
// Sample Output
// Yes
// No
// Yes
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
// System.out.println("n=" + n);
if(n != 0)
// if(in.hasNext())
// System.out.println();
{
while(true) {
int t = in.nextInt();
if(t == 0)
break;
else {
Stack<Integer> C = new Stack();
int [] target = new int[n];
target[0] = t;
for(int i = 1; i < n; i++) {
target[i] = in.nextInt();
}
int B = 0;
int A = 1;
while(A <= n) {
if(!C.empty() && C.peek() == target[B]) {
C.pop();
B++;
}
else {
C.push(A);
A++;
}
}
while(!C.empty()) {
if(!C.empty() && C.peek() == target[B]) {
C.pop();
B++;
}
else
break;
}
if(C.empty() && B == n)
System.out.println("Yes");
else
System.out.println("No");
}
}
if(in.hasNext())
System.out.println();
}
}
}
}
Uva 514 Rails java
最新推荐文章于 2021-03-03 16:38:27 发布