bzoj1628 [Usaco2007 Demo]City skyline(单调栈)
Description
Input
Output
输出一个整数,表示城市中最少包含的建筑物数量
Sample Input
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
#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(单调栈)的更多相关文章
- BZOJ1628: [Usaco2007 Demo]City skyline
1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 256 Solved: 210[Su ...
- 【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)
http://www.lydsy.com/JudgeOnline/problem.php?id=1628 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- BZOJ 1628 [Usaco2007 Demo]City skyline:单调栈
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1628 题意: 题解: 单调栈. 单调性: 栈内元素高度递增. 一旦出现比栈顶小的元素,则表 ...
- bzoj 1628: [Usaco2007 Demo]City skyline【贪心+单调栈】
还以为是dp呢 首先默认答案是n 对于一个影子,如果前边的影子比它高则可以归进前面的影子,高处的一段单算: 和他一样高的话就不用单算了,ans--: 否则入栈 #include<iostream ...
- HDU-4252 A Famous City(单调栈)
最后更新于2019.1.23 A Famous City ?戳这里可以前往原题 Problem Description After Mr. B arrived in Warsaw, he was sh ...
- BZOJ_1628_[Usaco2007_Demo]_City_skyline_(单调栈)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1628 给出\(n\)个距形的影子,问最少是多少个建筑的?(建筑的影子可以重叠). 分析 用单调 ...
- 小结:单调栈 & 单调队列
概要: 对于维护信息具有单调性的性质或者问题可以转化为具有单调性质的模型的题,我们可以考虑用单调栈或单调队列. 技巧及注意: 技巧很多,只要能将问题转化为单调性问题,就好解决了. 当维护固定长度的单调 ...
- HDOJ 4252 A Famous City 单调栈
单调栈: 维护一个单调栈 A Famous City Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- Gym 100971D Laying Cables 单调栈
Description One-dimensional country has n cities, the i-th of which is located at the point xi and h ...
随机推荐
- APP适配IOS8,iPhone6和Plus截图简要说明
本文转载至 http://blog.csdn.net/yongyinmg/article/details/41422873 原文:http://www.zcool.com.cn/article/ZMT ...
- java框架---->Xstream的使用(一)
Xstream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称.今天我们就简单的学习一下xstream的用法. Xstream的简单实例 项目的结构如下,设计到三个类 ...
- sencha touch 入门系列 (九)sencha touch 视图组件简介
对于一个普通用户来说,你的项目就是一组简单的视图集合,用户直接通过跟视图进行交互来操作你的应用,对于一个开发人员来说,视图是一个项目的入口,虽然大部分时候最有价值的部分是在model层和control ...
- fastcgi_param解释
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径 fastcgi_param QUERY_STRI ...
- SWT/JFace开发遇到org.eclipse.core.runtime.IProgressMonitor问题的解决办法(转载)
今日正在使用SWT和JFace开发一个系统,在搭建JFace平台时遇到了一个问题,运行HelloWorld程序抛出org.eclipse.core.runtime.IProgressMonitor的n ...
- 【node】------websocket------【巷子】
001.学习地址 https://github.com/websockets/ws 002.server.js //引入ws第三方模块 const WebSocket = require('ws'); ...
- 常用meta标签及说明
1.charset 定义文档的字符编码 例如: <meta charset="UTF-8"> 2. name 把 content 属性关联到一个名称,其属性有 ...
- 牛客网多校赛第七场--C Bit Compression【位运算】【暴力】
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524 ...
- docker基本操作命令
1. 构建镜像 docker build -t centos/tomcat:7.0 2. 创建一个容器 docker run --name test-tomcat centos/tomcat:7.0 ...
- spring boot实战(第一篇)第一个案例
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] spring boot实战(第一篇)第一个案例 前言 写在前面的话 一直想将spring boot相关内容写成一个系列的 ...