City Horizon
来源:互联网 发布:安装补丁的软件 编辑:程序博客网 时间:2024/05/16 10:19
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
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
42 5 19 10 46 8 24 6 3
Sample Output
16YYYYYYYYYYYYYYYYYYYYYYYYYY
注意各种__int64;
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int m;struct node{__int64 x,y,z,ans;}g[40005];__int64 cmp(node a,node b){if(a.z!=b.z)return a.z<b.z;if(a.y!=b.y)return a.y>b.y;if(a.x!=b.x)return a.x<b.x;}void cover(__int64 l,__int64 r,int h,int k){while(h<m&&(l>=g[h].y||r<=g[h].x)) h++;if(h>=m||r<=l){g[k].ans+=r-l;//当连续的一段被分成2部分是必须加一起;wa了n次;return;}if(l>=g[h].x&&r<=g[h].y) return;if(l<g[h].x){cover(l,g[h].x,h+1,k);}if(r>g[h].y) cover(g[h].y,r,h+1,k);}int main(){int i,j,k,n;while(scanf("%d",&m)!=EOF){memset(g,0,sizeof(g));for(i=0;i<m;i++){scanf("%I64d%I64d%I64d",&g[i].x,&g[i].y,&g[i].z);}//printf("\n\n");sort(g,g+m,cmp);for(i=m-1;i>=0;i--) cover(g[i].x,g[i].y,i+1,i);__int64 sum=0;/*for(i=0;i<m;i++)printf("%I64d %I64d %I64d\n",g[i].x,g[i].y,g[i].z);*//*for(i=0;i<m;i++) printf("%d \n",g[i].ans);*/for(i=0;i<m;i++){if(g[i].ans)sum+=g[i].ans*g[i].z;}printf("%I64d\n",sum);}return 0;}
- City Horizon
- City Horizon
- City Horizon
- poj 3277 City Horizon
- A City Horizon
- 【线段树】City Horizon
- poj 3277 City Horizon
- POJ 3277 City Horizon
- poj 3277 City Horizon
- POJ3277--City Horizon
- poj 3277 City Horizon
- poj3277 City Horizon
- POJ 3277 City Horizon
- POJ 3277 City Horizon
- POJ 3277 City Horizon
- poj3277 City Horizon
- POJ 3277 City Horizon
- [POJ]3277.City Horizon
- 使用Visual Studio 2005 IDE的宏,自动为c#变量生成属性
- asp.Net中Gridview动态创建模板列
- 管理员必备的20个Linux系统监控工具
- 痛苦的面试...
- 如何手工移动PE头
- City Horizon
- VC异常处理
- 第三章:Android中资源的访问
- QT设置标题栏左侧的ico图标和生成后的EXE文件图标的更换方法
- oracle数据库面试题目汇总
- iPhone 4S陷信号门:中移动频段被苹果阉割
- linux手动安装DB2及升级DB2
- HBase编程api介绍
- oracle 汇总