#include<iostream>
#include<stack>
#include<cstdio>
#define M 1005
using namespace std;
stack<int>stk;
int rail[M];
int main()
{
int i,j,k,n,p;
//freopen("in.txt","r",stdin);
while(scanf("%d",&n)&&n)
{
while(scanf("%d",&rail[1])&&rail[1])
{
for(i=2;i<=n;i++)
scanf("%d",&rail[i]);
p=1;
for(i=1;i<=n;i++)
{
if(rail[p]==i)
p++;
else
stk.push(i);
while(!stk.empty() && stk.top()==rail[p])
{
stk.pop();
p++;
}
}
if(stk.empty())
printf("Yes\n");
else
printf("No\n");
while(!stk.empty())
stk.pop();
}
printf("\n");
}
return 0;
}
#include<stack>
#include<cstdio>
#define M 1005
using namespace std;
stack<int>stk;
int rail[M];
int main()
{
int i,j,k,n,p;
//freopen("in.txt","r",stdin);
while(scanf("%d",&n)&&n)
{
while(scanf("%d",&rail[1])&&rail[1])
{
for(i=2;i<=n;i++)
scanf("%d",&rail[i]);
p=1;
for(i=1;i<=n;i++)
{
if(rail[p]==i)
p++;
else
stk.push(i);
while(!stk.empty() && stk.top()==rail[p])
{
stk.pop();
p++;
}
}
if(stk.empty())
printf("Yes\n");
else
printf("No\n");
while(!stk.empty())
stk.pop();
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.