spoj 95

时间:2021-11-11 01:20:32

栈应用 ...... 水题

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue> using namespace std; int a[1010], b[1010]; int main()
{
int n;
while(scanf("%d",&n) == 1 && n)
{
for(int i = 0; i < n; i++) scanf("%d",&a[i]);
int top = 0, ff = 0, bb = 1;
while(true)
{
while(top && b[top-1] == bb) top--, bb++;
if(a[ff] == bb) ff++, bb++;
else b[top++] = a[ff++];
if(ff == n+1) break;
}
if(bb == n+1) puts("yes");
else puts("no");
}
return 0;
}