铁轨

来源:互联网 发布:怎么删除mac上的照片 编辑:程序博客网 时间:2024/04/26 20:58


/*铁轨*/

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string>
using namespace std;
const int max = 1000;
int a[max];
int b[max];

int main()
{
 
 int n;
 while (scanf("%d",&n))
 {
 
  memset(a, 0, sizeof(a));
  for (int i = 1; i <= n; i++)
  {
   cin >> b[i];
  }//要求的顺序
  int j = 1;
  int ok = 1;
  int B = 1;
  int count = 0;
  while (ok!=0)
  {
   if (j == b[B])
   {
    j++;
    B++;
   }//找到已经进入C站的可以对应的第一个值
   else if (count&&a[count] == b[B])
   {
    count--;
    B++;
   }//找到可以对应的第一个值之后,释放储存的值
   else if (j <= n)
   {
    count++;
    a[count] = j;
    j++;
   }//在未找到最大值之前,先把数字储存起来
   else
   {
    ok = 0;
   }
  }
  printf("%s\n", ok == 0 ? "no" : "yes");
  
 }
 system("pause");
 return 0;
}

0 0