题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1683

Input

第1行:2个用空格隔开的整数N和W.

第2到N+1行:每行包括2个用空格隔开的整数x,y,其意义如题中所述.输入中的x严格递增,并且第一个z总是x.

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

感想

我困了!要睡觉!

题解

水题,只需维护单调递增栈即可

#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,ans,top,h[],st[];
int main(){
n=read();m=read();
for(int i=;i<=n;i++)h[i]=read(),h[i]=read();
ans=n;
for(int i=;i<=n;i++){while(st[top]>h[i])top--;if(st[top]==h[i])ans--;else st[++top]=h[i];}
printf("%d",ans);
return ;
}

bzoj1683[Usaco2005 Nov]City skyline 城市地平线的更多相关文章

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

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

  2. BZOJ 1683.City skyline 城市地平线

    传送门 从左到右扫一遍,考虑什么时候会和之前形成同一幢房子从而不用统计 显然是当前的高度和之前某个点高度相同,并且它们之间没有更矮的建筑 考虑用一个单调栈维护一个单调上升的房子轮廓,然后对于扫到的每一 ...

  3. 1645: [Usaco2007 Open]City Horizon 城市地平线

    1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 315  Solved: ...

  4. BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线

    BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线 Description N个矩形块,交求面积并. Input * Line 1: A single i ...

  5. 【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树

    [BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to ...

  6. bzoj1645 [Usaco2007 Open]City Horizon 城市地平线

    Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at ...

  7. 【BZOJ】1645: [Usaco2007 Open]City Horizon 城市地平线(线段树+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1645 这题的方法很奇妙啊...一开始我打了一个“离散”后的线段树.............果然爆了. ...

  8. BZOJ 1645: [Usaco2007 Open]City Horizon 城市地平线 扫描线 + 线段树 + 离散化

    Code: #include<cstdio> #include<algorithm> #include<string> #define maxn 1030000 # ...

  9. [USACO2005][POJ3044]City Skyline(贪心+单调栈)

    题目:http://poj.org/problem?id=3044 题意:以坐标的形式给出一张图,表示一些楼房的正视图,求出楼房的最少个数. 分析:和小学常做的立方体问题很像,很容易想到一个贪心方法, ...

随机推荐

  1. linux上的mysql配置过程

    自己阿里云上的服务器,记录下mysql的配置过程防止后面忘记 1. 首先用apt-get工具安装mysql sudo apt-get install mysql-server sudo apt-get ...

  2. centos7 --ngnix 常用命令:

    配置命令 随服务器启动 # systemctl enable nginx.service 重启 nginx 服务 # systemctl restart nginx.service 停止 nginx ...

  3. 为什么 jmeter 分布式测试,一定要设置 java.rmi.server.hostname

    之前总结了 jmeter 分布式测试的过程,在部署过程中提到,要在 system.properties 中配置自己的 IP. 至于为什么要这么做,源于这一次 debug 的过程. 运行环境 mint, ...

  4. 高可用OpenStack(Queen版)集群-3.高可用配置(pacemaker&haproxy)

    参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...

  5. nohup命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/hfismyangel/article/details/80258126 1.nohup 用途:不挂断地运行命令. 语法:n ...

  6. “Hello World!”团队第五周第七次会议

    博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.checkout&push代码 一.会议时间 2017年11月16日  ...

  7. 20172308 实验二《Java面向对象程序设计 》实验报告

    20172308 2017-2018-2 <程序设计与数据结构>实验2报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 周亚杰 学号:20172308 实验教师:王 ...

  8. 四则运算<C++>

    代码: #include<iostream> #define N 30 using namespace std; void main() { cout<<"***** ...

  9. 调研ANDRIOD平台的开发环境的发展演变

    在同学的推荐下,我选用学习eclipse这个软件,参考了这个网址的教程开始了一步一步的搭建之路. http://jingyan.baidu.com/article/bea41d437a41b6b4c5 ...

  10. Pytorch相关内容

    ---恢复内容开始--- Pytorch中文官方文档:https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch-nn P ...