USACO2005 City Skyline /// oj23401
题目大意:

* 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.
* Line 1: The minimum number of buildings to create the described skyline.
10 26
1 1
2 2
5 1
6 3
8 1
11 0
15 2
17 3
20 2
22 1
6
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 ;
}
USACO2005 City Skyline /// oj23401的更多相关文章
- BZOJ1628: [Usaco2007 Demo]City skyline
1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 256 Solved: 210[Su ...
- Leetcode 807 Max Increase to Keep City Skyline 不变天际线
Max Increase to Keep City Skyline In a 2 dimensional array grid, each value grid[i][j] represents th ...
- LC 807. Max Increase to Keep City Skyline
In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located the ...
- LeetCode #807. Max Increase to Keep City Skyline 保持城市天际线
https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/ 执行用时 : 3 ms, 在Max Increase to Ke ...
- [USACO2005][POJ3044]City Skyline(贪心+单调栈)
题目:http://poj.org/problem?id=3044 题意:以坐标的形式给出一张图,表示一些楼房的正视图,求出楼房的最少个数. 分析:和小学常做的立方体问题很像,很容易想到一个贪心方法, ...
- bzoj1683[Usaco2005 Nov]City skyline 城市地平线
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1683 Input 第1行:2个用空格隔开的整数N和W. 第2到N+1行:每行包括2个用空格 ...
- [Swift]LeetCode807. 保持城市天际线 | Max Increase to Keep City Skyline
In a 2 dimensional array grid, each value grid[i][j]represents the height of a building located ther ...
- [LeetCode] Max Increase to Keep City Skyline 保持城市天际线的最大增高
In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located the ...
- [LeetCode&Python] Problem 807. Max Increase to Keep City Skyline
In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located the ...
随机推荐
- (转)4年python,总结一些改善Python程序的建议
自己写Python也有四五年了,一直是用自己的"强迫症"在维持自己代码的质量.都有去看Google的Python代码规范,对这几年的工作经验,做个简单的笔记,如果你也在学pythp ...
- 2.4 webpack + gulp 构建完整前端工作流
在前面的两个小节中已经完整的讲了 webpack 和 gulp 相关的内容,本小节中将会结合二者构建一个完整的前端工作流,内容目录为: 前端工程结构和目标 前端工程目录结构 gulp clean gu ...
- Ethenet: MAC PHY MII RMII
https://www.cnblogs.com/liangxiaofeng/p/3874866.html 1. general 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成.DMA控制器 ...
- 与DSP通信时,RD&WR信号
/////////////////////////////////////////////////////////// :] rd,wr; :] dsp_data_out; 'hzzzz; // ...
- CodeForces1249E-By Elevator or Stairs?-好理解自己想不出来的dp
Input The first line of the input contains two integers nn and cc (2≤n≤2⋅105,1≤c≤10002≤n≤2⋅105,1≤c≤1 ...
- flink收藏博客
1.https://blog.csdn.net/liguohuabigdata/article/category/7279020 2.http://wuchong.me 3.https://www.j ...
- Editor REST Client
Editor REST Client 制作一个http请求 请求行 GET https://example.com/comments/1 HTTP/1.1 POST https://example.c ...
- 深入理解JAVA虚拟机原理之Dalvik虚拟机(三)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 本文是Android虚拟机系列文章的第三篇,专门介绍Andorid系统上曾经使用 ...
- layui的选项卡(tab)的问题
当页面打开单个tab时,操作栏显示: 当页面打开多个tab时,会发现操作栏与下面第一个tab显示的操作栏类型一样,并且操作栏的按钮无作用 第一个标签操作栏显示: 产生这样的原因:使用layui时,每个 ...
- D3.js绘制 颜色:RGB、HSL和插值 (V3版本)
颜色和插值 计算机中的颜色,常用的标准有RGB和HSL. RGB:色彩模式是通过对红(Red).绿(Green).蓝(Blue)三个颜色通道相互叠加来得到额各式各样的颜色.三个通道的值得范围都 ...