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 ...
随机推荐
- 从TCP三次握手说起--浅析TCP协议中的疑难杂症(1)
版权声明:本文由黄日成原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/73 来源:腾云阁 https://www.qclou ...
- sonar-scanner扫描代码出错 SonarQube svn: E170001
问题报错: Caused by: org.tmatesoft.svn.core.SVNAuthenticationException: svn: E170001: Authentication req ...
- 微信小游戏 查看egret的小游戏支持库版本
在开发者工具 console输入egret.wxgame
- PHP概率算法---砸金蛋示例
这是一个很经典的概率算法: function get_rand($proArr) { $result = ''; //概率数组的总概率精度 $proSum = array_sum($proArr); ...
- js获取元素的外链样式
一般给元素设置行内样式,如<div id="div1" style="width:500px;"></div>.如要获取它的样式,即可d ...
- Python+ Calibre 处理 中文报纸
import re ##2 line='<a href=nw.D110000renmrb_20180401_1-01.htm><script>document.write(vi ...
- Python大数据:外部数据获取(网页抓取)
import urllib2 as url import cookielib,StringIO,gzip,json import pandas as pd import numpy as np #定义 ...
- Python开发【Tornado】:异步Web服务(二)
真正的 Tornado 异步非阻塞 前言: 其中 Tornado 的定义是 Web 框架和异步网络库,其中他具备有异步非阻塞能力,能解决他两个框架请求阻塞的问题,在需要并发能力时候就应该使用 Torn ...
- linux 的nohup & 和daemon 总结(转)
add by zhj:守护进程貌似跟nohup + &方式启动的进程差不多.都可以实现与终端的无关联. 原文:http://blog.csdn.net/lovemdx/article/de ...
- centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课
centos shell编程4[分发系统] 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要 ...