City Horizon
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 17061 |
|
Accepted: 4653 |
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.
Source
USACO 2007 Open Silver
题意:有n做建筑在一个坐标轴上(想象在坐标轴上),三个数分别表示为建筑在坐标轴上的起点 终点 建筑的高度,然后求所有建筑面积的和(可能会出现两个建筑有一部分重合,这样的话重合的部分算一次就可以了)
思路:该题的做法和poj1389的思路差不多,不同的是1389是从上到下扫描,而本题是从左到右进行扫描。两个题几乎是一样的。
#include
#include
#include
#include
#include
#define N 40011
using namespace std;
struct node
{
long long int lf,rf;
long long int cnt,ans;
long long int l,r;
}q[N>1;
build(l,mid,rt 0)
{
q[rt].cnt = q[rt].rf - q[rt].lf;
return ;
}
else
{
q[rt].cnt = 0;
}
if(q[rt].l + 1 == q[rt].r)
{
return ;
}
else
{
q[rt].cnt = q[rt=dot.x2)
{
insert(rt
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net