BZOJ_1628_[Usaco2007_Demo]_City_skyline_(单调栈)
2016-07-09 10:25
330 查看
描述
http://www.lydsy.com/JudgeOnline/problem.php?id=1628
给出\(n\)个距形的影子,问最少是多少个建筑的?(建筑的影子可以重叠).
分析
用单调栈维护一下.
栈内是可能"延续"到当前位置的之前的影子.那么显然比当前位置高的不可能.如果有和当前位置等高的影子,就延续过来,就可以少一个建筑,否则,就向栈里加入当前位置高度的影子.
#include <bits/stdc++.h> using namespace std; const int maxn=50000+5; int n,m,top,ans; int a[maxn],s[maxn]; int main(){ scanf("%d%d",&n,&m); ans=n; for(int i=1;i<=n;i++) scanf("%d",&a[i]), scanf("%d",&a[i]); for(int i=1;i<=n;i++){ while(s[top]>a[i]) top--; if(s[top]==a[i]) ans--; else s[++top]=a[i]; } printf("%d\n",ans); return 0; }View Code
1628: [Usaco2007 Demo]City skyline
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 432 Solved: 344
[Submit][Status][Discuss]
Description
Input
第一行给出N,W 第二行到第N+1行:每行给出二个整数x,y,输入的x严格递增,并且第一个x总是1Output
输出一个整数,表示城市中最少包含的建筑物数量
Sample Input
10 261 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
6HINT
Source
相关文章推荐
- Android JavaPoet 动态生成Java源码(1)
- JavaWeb三层结构---课设02
- Linux内核---47.关于clk_get与clk_enable
- Cocos2d-3.x触摸事件 中 setSwallowTouches
- iOS开发 刮刮乐效果的实现
- Super VLAN
- poj滑雪(记忆化搜索)
- 克隆虚拟机
- Objective-C规范注释心得——同时兼容appledoc(docset、html)与doxygen(html、pdf)的文档生成
- POJ1011
- Linux内核---46.关于mem_map
- BZOJ2850 巧克力王国
- Linux内核---45.关于initcall
- scrapy简单爬取内容
- java的安装和配置
- Attribute is missing the Android namespace prefix问题
- Linux内核---44.关于中断号与中断引脚
- jQuery Easyui学习教程之实现datagrid在没有数据时显示相关提示内容
- c 语言中宏定义和定义全局变量的区别
- 【Win 10 应用开发】导入.pfx证书