zoukankan      html  css  js  c++  java
  • [Usaco2007 Demo][BZOJ1628] City skyline

    1628: [Usaco2007 Demo]City skyline

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 320  Solved: 260
    [Submit][Status][Discuss]

    Description

    Input

    第一行给出N,W
    第二行到第N+1行:每行给出二个整数x,y,输入的x严格递增,并且第一个x总是1

    Output

    输出一个整数,表示城市中最少包含的建筑物数量

    Sample Input

    10 26
    1 1
    2 2
    5 1
    6 3
    8 1
    11 0
    15 2
    17 3
    20 2
    22 1

    INPUT DETAILS:

    The case mentioned above

    Sample Output

    6

    HINT

     

    Source

     
    单调栈
    首先至多有n个建筑物,如果有两个高度相等的楼且这两栋楼之间没有比这些楼更矮的楼,那么建筑物数量就可-1。
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<set>
    using namespace std;
    int n,x,w,h[50005],ans,top,stack[50005];
    int main()
    {
        scanf("%d%d",&n,&w);
        ans=n; 
        for (int i=1;i<=n;i++) scanf("%d%d",&x,&h[i]);
        for (int i=1;i<=n;i++) 
        {
            while (h[i]<stack[top]) top--;
            if (h[i]==stack[top]) ans--;
                else stack[++top]=h[i];
        }
        printf("%d",ans);
        return 0;
    }
  • 相关阅读:
    动物-昆虫:蠼螋
    动物-昆虫:蚰蜒
    动物-软体动物:蜒蚰
    动物-昆虫:蝼蛄
    动物-昆虫:地鳖
    动物:水蛭、蚂蟥
    动物:刺猬
    cmd 下命令
    storm-安装
    python学习之--安装IDE(eclipse+pydev)
  • 原文地址:https://www.cnblogs.com/ws-fqk/p/4668063.html
Copyright © 2011-2022 走看看