设为首页 加入收藏

TOP

POJ训练计划3277_City Horizon(扫描线/线段树+离散)
2015-07-20 17:56:28 来源: 作者: 【 】 浏览:3
Tags:POJ 训练 计划 3277_City Horizon 扫描 线段 离散

解题报告

题目传送门

题意:

水平看城市,也就是正视图,给定每一栋楼的左右坐标和高度。求看到的城市楼的面积。

下图是测试数据的图。

\

思路:<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+yajD6M/fx/PD5rv9sqKhozwvcD4KPHA+sru74cmow+jP37XEv7TPwsPmtcSyqb/NoaM8L3A+CjxwPmh0dHA6Ly93d3cuY25ibG9ncy5jb20vc2NhdTIwMTEwNzI2L2FyY2hpdmUvMjAxMy8wNC8xMi8zMDE2NzY1Lmh0bWw8YnI+CjwvcD4KPHA+wOvJorSmwO3X+LHqKNPJ09rA68miuvO1xNf4serKx7Xjo6y2+M/fts7K97XEw7/Su7j2tePKx9K7uPbH+Lzko6zL+dLU0qq21NOmxvDAtKOsv8nS1LDRx/i85MDryaK689PS1/ix6i0xKaOsz9+2zsr3zqy7pMmow+jP37OktsihozwvcD4KPHA+z9+2zsr3zqy7pMmow+jP37OktsijujwvcD4KPHA+bHrK/dfpseq8x8f4vOSxu7bgydnM9c/fuLK4x6Osc3Vtyv3X6cfzx/i85MTayajD6M/ftcSzpLbIoaM8L3A+CjxwPnBzo7q/ycTcu+GzrGludDwvcD4KPHA+PHByZSBjbGFzcz0="brush:java;">#include #include #include #include #define LL long long using namespace std; struct Seg { LL l,r,h; int v; friend bool operator < (Seg a,Seg b) { return a.h r||qr

City Horizon
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 16207 Accepted: 4415

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. Building i's silhouette has a base that spans locations Ai through Bi along the horizon (1 ≤ Ai < Bi ≤ 1,000,000,000) and has height Hi (1 ≤ Hi ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by all N 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 all N buildings

Sample Input

4
2 5 1
9 10 4
6 8 2
4 6 3

Sample Output

16

Hint

The first building overlaps with the fourth building for an area of 1 square unit, so the total area is just 3*1 + 1*4 + 2*2 + 2*3 - 1 = 16.
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 1885 Key Task 状态压缩+搜索 下一篇hdu 2177 取(2堆)石子游戏

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: