您的位置:首页 > 其它

1113: [Poi2008]海报PLA 单调栈

2016-01-11 22:57 204 查看
今天看SAM好久还是没看懂。。傻逼题调一晚上。。真是不爽。。

赶紧屠几道水题。。

可以发现如果出现 h1 < h2 > h3 且h1==h3时,我们可以用一个矩形来覆盖这一块,ans可以减一。所以我们可以维护一个单调栈。

[code]#include<bits/stdc++.h>
using namespace std;
int n,ans,top;
int s[250005];
inline int read()
{
    int a=0,f=1; char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
    while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
    return a*f;
}
int main()
{
    n=read(); ans=n;
    for (int i=1;i<=n;i++)
    {
        int x=read(),y=read();
        while (y<=s[top])
        {
            if (y==s[top]) ans--;
            top--;
        }
        s[++top]=y;
    }
    cout << ans;
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: