zoukankan      html  css  js  c++  java
  • BZOJ 1683.City skyline 城市地平线

    传送门

    从左到右扫一遍,考虑什么时候会和之前形成同一幢房子从而不用统计

    显然是当前的高度和之前某个点高度相同,并且它们之间没有更矮的建筑

    考虑用一个单调栈维护一个单调上升的房子轮廓,然后对于扫到的每一个高度,看看栈里有没有相同的高度就行了

    但是我比较傻逼,没想到,所以用 $set$ 去维护单调栈就可以维护的东西...

    每个位置进出 $set$ 一次,复杂度 $O(n log n)$

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<set>
    using namespace std;
    inline int read()
    {
        int x=0,f=1; char ch=getchar();
        while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
        while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    const int N=5e5+7;
    int n,m,ans;
    set <int> S;
    set <int>::iterator it,pit;
    int main()
    {
        n=read(),m=read();
        int x,y; S.insert(0);
        for(int i=1;i<=n;i++)
        {
            x=read(),y=read();
            for(it=S.upper_bound(y);it!=S.end();it=S.upper_bound(y)) S.erase(it);
            if(S.find(y)==S.end()) { ans++; S.insert(y); }
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    paip.关于动画效果的原则 html js 框架总结
    一个二维阵列蛇的实现
    数据验证validator 与 DWZ
    20140704, 七月微软安全补丁的通知
    oracle9
    oracle8
    oracle7
    oracle6
    Java正常关闭资源的方式
    oracle5
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11320741.html
Copyright © 2011-2022 走看看