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 ...
随机推荐
- ajax - getJSON() 方法
$("body").on("click",".layui-input-inline:eq(3)",function(){ $(this).f ...
- 【Java多线程系列一】Java实现线程方法
Java实现线程的两种方法 继承Thread类 实现Runnable接口 它们之间的区别如下: Java的类为单继承,但可以实现多个接口,因此Runnable可能在某些场景比Thread更适用 Thr ...
- (转载)理解和使用Promise.all和Promise.race
声明:本文转载自:https://www.jianshu.com/p/7e60fc1be1b2 一.Pomise.all的使用 Promise.all可以将多个Promise实例包装成一个新的Prom ...
- 前端(十五)—— JavaScript事件:绑定事件方式、事件的冒泡和默认事件、鼠标事件、键盘事件、表单 事件、文档事件、图片事件、页面事件
JS事件:绑定事件方式.事件的冒泡和默认事件.鼠标事件.键盘事件.表单 事件.文档事件.图片事件.页面事件 一.事件的两种绑定方式 1.on事件绑定方式 document.onclick = func ...
- 使用target属性跳转到指定位置
先上代码,使用frameset将网页分割为三个窗口,上,左和右. 1 <html> 2 <head> 3 <title>Main</title> 4 & ...
- Spring MVC源码分析(二):SpringMVC的DispatcherServlet的设计与实现
概述 DispatcherServlet是SpringMVC的一个前端控制器,是MVC架构中的C,即controller的实现,用于拦截这个web应用的所有请求,具体为在web.xml中配置这个s ...
- 利用MySqlBulkLoader生成csv文件,批量添加数据
DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Yw ...
- axios获取本地文件配置步骤
首先修改一下config文件夹下面的index.js文件里面的配置,如下: 然后 ,通过axios 请求配置的接口 <script> import axios from 'axios' e ...
- webpack4.x的使用历程
第一次接触的webpack是在一个3.x的资料中 在4.x的运用中遇到了好多的坑,我就以小白的身份把我使用webpaxk的过程分享出来,其中很多不足欢迎大佬们指正 node安装不再赘述 一.安装 np ...
- JS window对象 History 对象 history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。语法: window.history.[属性|方法]
History 对象 history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能. 注意:从窗口被打开的那一刻开始记录,每个浏览器窗口.每个标签页乃至每个框架,都 ...