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
 

题目的$w$没有意义
我们发现高度$h$出现一次时,答案+1
$h$在一个先增后降的序列中出现两次时,显然答案也只要+1
那么我们可以设$ans=n$
考虑维护一个单调递增栈,当某个数出现2次时,$ans-1$即可
 #include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
int n,q,h,w,st[],tp,ans;
int main(){
scanf("%d%d",&n,&w); ans=n;
for(re int i=;i<=n;++i){
scanf("%d%d",&q,&h);
while(tp&&st[tp]>h) --tp;
if(st[tp]==h) --ans;
else st[++tp]=h;
}printf("%d",ans);
return ;
}
 

bzoj1628 [Usaco2007 Demo]City skyline(单调栈)的更多相关文章

  1. BZOJ1628: [Usaco2007 Demo]City skyline

    1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 256  Solved: 210[Su ...

  2. 【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id ...

  3. BZOJ 1628 [Usaco2007 Demo]City skyline:单调栈

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1628 题意: 题解: 单调栈. 单调性: 栈内元素高度递增. 一旦出现比栈顶小的元素,则表 ...

  4. bzoj 1628: [Usaco2007 Demo]City skyline【贪心+单调栈】

    还以为是dp呢 首先默认答案是n 对于一个影子,如果前边的影子比它高则可以归进前面的影子,高处的一段单算: 和他一样高的话就不用单算了,ans--: 否则入栈 #include<iostream ...

  5. HDU-4252 A Famous City(单调栈)

    最后更新于2019.1.23 A Famous City ?戳这里可以前往原题 Problem Description After Mr. B arrived in Warsaw, he was sh ...

  6. BZOJ_1628_[Usaco2007_Demo]_City_skyline_(单调栈)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1628 给出\(n\)个距形的影子,问最少是多少个建筑的?(建筑的影子可以重叠). 分析 用单调 ...

  7. 小结:单调栈 & 单调队列

    概要: 对于维护信息具有单调性的性质或者问题可以转化为具有单调性质的模型的题,我们可以考虑用单调栈或单调队列. 技巧及注意: 技巧很多,只要能将问题转化为单调性问题,就好解决了. 当维护固定长度的单调 ...

  8. HDOJ 4252 A Famous City 单调栈

    单调栈: 维护一个单调栈 A Famous City Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  9. Gym 100971D Laying Cables 单调栈

    Description One-dimensional country has n cities, the i-th of which is located at the point xi and h ...

随机推荐

  1. Android 权限信息

    访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permiss ...

  2. Android开发 Android Studio2.0 教程从入门到精通Windows版 - 入门篇

    第一篇 介绍了Android Studio开发环境以及Genymotion虚拟机安装方法,本节将给大家介绍如何使用Android Studio开发应用. 开发第一应用 可以开发属于自己的应用,是否有点 ...

  3. HTTP/2笔记之帧

    零.前言 客户端和服务器端一旦握手协商成功接建立连接,端点之间可以基于HTTP/2协议传递交换帧数据了. 一.帧通用格式 下图为HTTP/2帧通用格式:帧头+负载的比特位通用结构: +-------- ...

  4. 开源的PaaS方案:在OpenStack上部署CloudFoundry (二)部署OpenStack

    硬件要求 安装OpenStack 1 安装CentOS 65系统并清空iptables防火墙规则 2 安装系统需要的工具包包括Openstack依赖的和CloudFoundry依赖的 3 安装EPEL ...

  5. jquery类似方法的比较(二)

    (1)append()&appendTo()&prepend()$prependTo() (2)after()&before()&insertAfter()&i ...

  6. Android 7.1 SystemUI--任务管理--场景一:长按某个缩略图,拖动分屏的流程

    TaskView 类的长按事件 onLongClick 方法内发送了 DragStartEvent 事件消息,该 DragStartEvent 事件消息由 RecentsView,TaskStackV ...

  7. 【黑金ZYNQ7000系列原创视频教程】03.体验FPGA里的ARM——裸机helloworld实验

    黑金论坛地址: http://www.heijin.org/forum.php?mod=viewthread&tid=36637&extra=page%3D1 爱奇艺地址: http: ...

  8. select标签的onchange事件

    /** @1.onchange事件 ==> select选择事件* @2.obj.options ==> 选择option集合* @3.obj.selectedIndex ==> 选 ...

  9. RAID和LVM磁盘阵列

    RAID磁盘冗余阵列 CPU的处理性能保持着高速增长,Intel公司在2017年最新发布的i9-7980XE处理器芯片更是达到了18核心36线程.但与此同时,硬盘设备的性能提升却不是很大,因此逐渐成为 ...

  10. DetaSet更新数据

    用到的控件:DataGridView(展示数据),                    Button控件,更名[更新] using System; using System.Collections. ...