【Lintcode】Building Outline
2016-02-19 20:31
477 查看
class Solution { public: /** * @param buildings: A list of lists of integers * @return: Find the outline of those buildings */ set<int> loc; map<int,vector<int>> st,en; multiset<int> H; vector<vector<int>> buildingOutline(vector<vector<int>> &buildings) { // write your code here vector<vector<int>> ret; for (auto x : buildings) { loc.insert(x[0]); loc.insert(x[1]); st[x[0]].push_back(x[2]); en[x[1]].push_back(x[2]); } int H0 = 0; int X0 = 0; H.insert(0); for (auto X1 : loc) { auto H1 = *H.rbegin(); if (H1) { if (ret.empty() || H1 != ret[ret.size() - 1][2]) ret.push_back(vector<int>{X0,X1,H1}); else ret[ret.size() - 1][1] = X1; } for (auto x : st[X1]) H.insert(x); for (auto x : en[X1]) H.erase(H.find(x)); X0 = X1; } return ret; } };
特别要注意,multiset删除某个元素的一个副本和所有副本的区别。
H.erase(x) 会删除 x 的所有副本
我不知道wa了一次嘿嘿,当然之前还ce了5,6次。。
相关文章推荐
- HDU 4908 BestCoder Sequence
- Easyui-datagrid显示时间的格式化代码
- EasyUI系列学习(七)-Linkbutton(按钮)
- iOS UISearchBar学习笔记
- 你所不知道的UITabBarButton?
- java(15)--servlet中Request相关知识
- 频率特性曲线_20160218
- ZOJ-2966-Build The Electric System【5th浙江省赛】【最小生成树】
- NGUI利用两个摄像机裁剪特效
- iOS开发之UICollectionView
- UI到底应该用xib/storyboard完成,还是用手写代码来完成?
- quick-mark: How Latency is Measured
- Animation动画详解(四)——ValueAnimator基本使用
- LeetCode -- Product of Array Except Self My Submissions Question
- iOS 8及以后版本 如何创建UIAlertView?
- js中return;、return true、return false;区别
- UITableView的优化
- Android Volley完全解析(三),定制自己的Request
- ZOJ 2966 Build The Electric System(最小生成树)
- iOS设计UI工具大全