#include<iostream>
#include<string.h>
#include<string>
#include<stack>
#include<stdlib.h>
#include<vector>
#include<math.h>
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int n;
vector<int> block[30];
int t[1010];
int main()
{
int a, b,i,flag;
while (~scanf("%d", &n)&&n)
{
while (scanf("%d", &t[0]), t[0])
{
a = flag = 1;
b = 0;
for (i = 1; i < n; i++)
scanf("%d", &t[i]);
stack<int>s;
while (b < n)
{
if (a == t[b])
{
a++;
b++;
}
else if (!s.empty() && s.top() == t[b])
{
s.pop();
b++;
}
else if (a <= n)
{
s.push(a++);
}
else
{
flag = 0;
break;
}
}
if (flag == 1)
printf("Yes\n");
else
printf("No\n");
}
printf("\n");
}
return 0;
}
B - Rails
最新推荐文章于 2023-07-25 11:28:42 发布