题目大意:

Input

* Line 1: Two space separated integers: N and W

* Lines 2..N+1: Two space separated integers, the x and y coordinate of a point where the skyline changes. The xcoordinates are presented in strictly increasing order, and the first x coordinate will always be 1.

Output

* Line 1: The minimum number of buildings to create the described skyline.

Sample Input

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

Sample Output

6

Hint

INPUT DETAILS:

The case mentioned above

需要找到规律

题解:
模拟一个单调栈,使栈内的元素递增。
当新进来一个元素x时,while栈顶的元素大于当前x,ans++,将栈顶元素弹出
如果栈顶元素等于x则只保留一个,ans不变
最后加进去一个0元素把栈按照上述方式清空即可

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,w;
while(~scanf("%d%d",&n,&w))
{
stack <int> s;
while(!s.empty()) s.pop();
int a,b,ans=;
for(int i=;i<=n;i++)
{
if(i==n) b=;
else scanf("%d%d",&a,&b);
if(!s.empty())
{
while(!s.empty()&&b<s.top())
{
ans++;
s.pop();
}
if(!s.empty()&&b==s.top()) s.pop();
s.push(b);
}
else s.push(b);
}
printf("%d\n",ans);
} return ;
}

最新文章

  1. Android开发之画图的实现
  2. TOP 和 OFFSET 筛选(转)
  3. GridView基础知识
  4. 如何准确高效的获取数据库新插入数据的主键id
  5. 基于weka的文本分类实现
  6. 剑指架构师系列-Hibernate需要掌握的Annotation
  7. Codeforces Round #230 (Div. 2) 解题报告
  8. 百度 UEditor 简单安装调试和调用,网上其它的教程太官方了,不适合新手
  9. js关闭页面(兼容浏览器)
  10. 【spoj SEQN】【hdu 3439】Sequence
  11. 爬虫技术实战 | WooYun知识库
  12. 使用systemtap调试linux内核
  13. 进程间通信系列 之 命名管道FIFO及其应用实例
  14. Navicat11全系列激活(注册机)
  15. WPF 设置输入只能英文
  16. 为label或者textView添加placeHolder
  17. R-CNN,SPP-NET, Fast-R-CNN,Faster-R-CNN, YOLO, SSD, R-FCN系列深度学习检测方法梳理
  18. 基于nginx+xxl-job+springboot高可用分布式任务调度系统
  19. BeanUtils工具的使用
  20. python进行数据分析------相关分析

热门文章

  1. SpringBoot项目框架下ThreadPoolExecutor线程池+Queue缓冲队列实现高并发中进行下单业务
  2. ajax 重复提交
  3. csv 基本操作, 报错解决(UnicodeEncodeError: &#39;utf-8&#39; codec can&#39;t encode characters in position 232-233: surrogates not allowed)
  4. Java 序列化和反序列化(三)Serializable 源码分析 - 2
  5. python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)
  6. 自学Oracle心得
  7. windows 开启管理员权限
  8. boost asio tcp 多线程
  9. python_django_template_url反向解析
  10. 解决在移动端上 click事件延迟300 毫秒的问题 fastclick.js