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;
    }
  • 相关阅读:
    PHP下实现两种ajax跨域的解决方案之jsonp
    实际应用中git(合并本地与服务器项目)
    centos7 编译安装nginx
    windows vagrant共享目录设置问题
    shell 需要注意的点
    插入排序(直接插入排序)
    选择排序
    快速排序
    冒泡排序
    centos7.5安装redis-5.0.4
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11320741.html
Copyright © 2011-2022 走看看