The Skyline Problem解题报告
来源:互联网 发布:湖北文理学院网络 编辑:程序博客网 时间:2024/05/16 14:44
https://leetcode.com/problems/the-skyline-problem/
这道题是根据数据对勾勒出数据的外形。数据的外形只和左边线和高度有关。因为数据已经按照左边线做了升序处理,所以我们不需要考虑序列的问题。外部的轮廓有所改变会出现两种情况:一是出现拐点,在一片相交连续的区域内有高度不同。二是出现空隔,空隔是将要开始扫描的左边线比已经存储右边线还要大,这时出现空隔。因此我们使用priority_queue数据结构存储已经使用过的建筑的高度和右边线。当当前建筑有交集高度变化则将该建筑插入priority_queue中,否则将queue清空,重新开始。
class Solution {public: vector<pair<int, int>> getSkyline(vector<vector<int>>& buildings) { vector<pair<int, int>> res; if(buildings.size()==0) return res; priority_queue<pair<int,int> > livbld; int cur=0; int curX=-1,curH=-1,len=buildings.size(); while(cur<len||!livbld.empty()){ curX=livbld.empty()?buildings[cur][0]:livbld.top().second; if(cur>=len||buildings[cur][0]>curX){ while(!livbld.empty()&&(livbld.top().second<=curX)) livbld.pop(); } else{ curX=buildings[cur][0]; while(cur<len&&buildings[cur][0]==curX){ livbld.push(make_pair(buildings[cur][2], buildings[cur][1])); cur++; } } curH=livbld.empty()?0:livbld.top().first; if(res.empty() || (res.back().second != curH) ) res.push_back(make_pair(curX, curH)); } return res; }};
0 0
- The Skyline Problem解题报告
- LeetCode-The Skyline Problem-解题报告
- [leetcode] 218. The Skyline Problem 解题报告
- [Leetcode] 218. The Skyline Problem 解题报告
- The Skyline Problem解题心得
- 105 - The Skyline Problem
- leetcode - The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- LeetCode - The Skyline Problem
- leetcode:the skyline problem
- LeetCode218:The Skyline Problem
- The Skyline Problem -- leetcode
- Leetcode -- The Skyline Problem
- 218 .The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- PHP Ajax 跨域问题最佳解决方案
- js 静态私有变量
- 几行代码快速集成二维码扫描库
- 用汇编得到变量地址
- Android视频播放器开发—— 探究MediaPlayer
- The Skyline Problem解题报告
- 简单的多线程实例C++
- Codeforces Round #388(Div. 2)A. Bachgold Problem【水题】
- Python基础
- 第一个web程序总结
- linux:jdk的安装
- 用installAnywhere2009 打包安装java web程序 (详细图表操作)
- Web项目部署到Linux服务器
- Hibernate简单实例