[BZOJ1683][Usaco2005 Nov]City skyline 城市地平线(单调栈)

题目描述

传送门

题解

和海报那道题基本一样。

代码

#include
#include
#include
using namespace std;

int n,w,x,y,temp,ans;
int strack[5005];

int main()
{
    scanf("%d%d",&n,&w);
    strack[++temp]=0;
    for (int i=1;i<=n;++i)
    {
        scanf("%d%d",&x,&y);
        while (temp&&y<=strack[temp])
        {
            if (strack[temp]==y) ans++;
            temp--;
        }
        strack[++temp]=y;
    }
    printf("%d\n",n-ans);
}

你可能感兴趣的:(题解,单调栈,BZOJ,单调栈)