TOJ 1706: City Horizon -- 线段树,平衡树
来源:互联网 发布:js自动答题代码 编辑:程序博客网 时间:2024/06/06 02:15
1706: City Horizon
Total Submit: 44 Accepted:11
Description
Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings.
The entire horizon is represented by a number line with N (1 ≤ N ≤ 40,000) buildings. Buildingi's silhouette has a base that spans locationsAi throughBi along the horizon (1 ≤ Ai <Bi ≤ 1,000,000,000) and has heightHi (1 ≤Hi ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by allN buildings.
Input
Line 1: A single integer:N
Lines 2..N+1: Input line i+1 describes building i with three space-separated integers:Ai,Bi, and Hi
Output
Line 1: The total area, in square units, of the silhouettes formed by allN buildings
Sample Input
42 5 19 10 46 8 24 6 3
Sample Output
16
Hint
Source
USACO Open 2007
分析:这道题用线段树做很简单,不过偶然看到自己以前写的代码,那时还不知道线段树,甚至不知道STL。。。于是排序算法和树操作都是自己写的(只是普通的二叉树,那时应该也不会写平衡树。。。)反正就这样把这题给写出来了。。。
思路很简单,把所有坐标排序,然后从左向右扫描,始终记录当前最高高度。遇到区间起点就向树中插入结点,同时更新高度,遇到区间终点就删除结点,同时找到现有的最大高度。因为要用DELETE和EXTRACT-MAX操作,就用的二叉树。
- TOJ 1706: City Horizon -- 线段树,平衡树
- 【线段树】City Horizon
- 【POJ3277】City Horizon,线段树
- poj -- 3277City Horizon (线段树)
- poj3277 City Horizon(离散化+线段树)
- poj 3277 city horizon 线段树
- POJ 3277 City Horizon 线段树
- City Horizon poj3277 线段树+离散化
- poj 3277 City Horizon 线段树
- Poj 3277 City Horizon - 线段树
- pku 3277 City Horizon(离散化+线段树)
- PKU 3327City Horizon离散化+线段树
- (离散化 + 线段树) poj 3277 City Horizon
- poj 3277 City Horizon(线段树#2----离散化)
- HDU 3277 City Horizon(线段树 + 离散化)
- POJ 3277 City Horizon 扫描线+离散化+线段树
- poj-3277-City Horizon-离散化+线段树区域更新
- POJ 3277 City Horizon (离散化线段树)
- 路由中的shells / CLI
- 使用隐式转换auto_ptr导致程序崩溃原因
- JavaScript操作表格代码
- C语言使用socket通过IP138获取外网IP
- C# 之 枚举与结构
- TOJ 1706: City Horizon -- 线段树,平衡树
- .net micro framework的入门例程-点灯神话-2.按键控制LED灯
- nefu 635 Twinkle Twinkle Little Star
- SSH2下使用ajaxFileUpload控件上传附件
- Windows下notepad++配置java编译环境
- 无线客户端应该如何选择rpc服务
- 全排列
- C语言SOCKET获取本机所有IP
- .net micro framework的入门例程-点灯神话-3.按键中断控制LED