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 ...
随机推荐
- H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)
题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 Given n positive integers , your task is to calculat ...
- 一:unittest框架配合selenium工具之CSS_selector定位。
做了自动化测试这么久了,一直没有梳理到元素定位这一块的内容,其重要性不言而喻.趁着周末有时间,梳理一下. 1,通过id定位 driver.find_element_by_css_selector(&q ...
- db2,用户名密码不对导致无法连接数据库: Reason: User ID or Password invalid. ERRORCODE=-4214, SQLSTATE=28000
文章目录 背景 解决 背景 qa需要db2的demo,运维给安装完db2,启动报错 com.ibm.db2.jcc.am.io: [jcc][t4][2013][11249][4.7.112] Con ...
- MySQL之explain命令解释
explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了.如: explai ...
- 广度优先搜索(Breadth First Search)
Date:2019-07-03 14:29:02 走完一层的所有房间,再走下一层,用队列实现 算法实现 /*--------------------------模版------------------ ...
- pta作业1
7-1 打印沙漏 (20 分) 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数 ...
- 净心诀---python3装饰器
python3装饰器 装饰器作用 简单理解:可以为已有函数添加额外功能 例: 已有2个函数如下 def MyFunc1(): print("This is a print function1 ...
- @ApiImplicitParams、ApiImplicitParam的使用
@ApiImplicitParam:作用在方法上,表示单独的请求参数 参数: 1. name :参数名. 2. value : 参数的具体意义,作用. 3. required : 参数是否必填. 4. ...
- http://localhost:8080 is requesting your username and password
after you startup your tomcat, you type a concrete request url in broswer, the tomcat probably wil ...
- css 折角效果/切角效果
首先我们先创建一个图案为100像素的斜面切角的图案 html <div class="one">12345</div> css .one{ width: 1 ...