#include <iostream>
#include <algorithm>
#include <cstring>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
const int N =1005;
int stack[N],a[N];
int top,n;
int main(int argc, char** argv) {
cin>>n;
for(int i=0; i<n ; i++){
cin>>a[i];
}
top=-1;
for(int i=0,cur=0; i<n ;i++){ //cur当前可以入栈的元素
while(cur<=a[i]){
stack[++top]=cur++; //把计划输出的元素放到栈顶,便于输出
}
if(stack[top]==a[i])
--top;
else
{
cout<<"no";
return 0;
}
}
cout<<"yes";
return 0;
}
车厢调度问题
最新推荐文章于 2023-08-08 15:38:23 发布