BZOJ 1113: [Poi2008]海报PLA

来源:互联网 发布:萧山哪里有学编程 编辑:程序博客网 时间:2024/05/20 19:16

水题

记得当初考试的时候是用堆水过去的...

正解单调栈

#include<cstdio>using namespace std; int n,top,ans;int s[250001]; int main(){    scanf("%d",&n);    for(int i=1;i<=n;++i)    {        int x,y;        scanf("%d %d",&y,&x);        while(x<=s[top])        {            if(x==s[top]) ++ans;            --top;        }        s[++top]=x;    }    printf("%d\n",n-ans);}


原创粉丝点击