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;
    }
  • 相关阅读:
    MySQL数据表类型 = 存储引擎类型
    删除链表节点
    链表逆序(反转)
    腾讯2012笔试题
    MysqL数据表类型
    进程间的通信方式
    网络套接字编程学习笔记一
    HTTP报头
    C语言排序算法
    交换排序经典的冒泡排序算法总结
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11320741.html
Copyright © 2011-2022 走看看