spoj 95

来源:互联网 发布:快递数据 编辑:程序博客网 时间:2024/05/02 05:02

栈应用 ...... 水题

#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;}



原创粉丝点击