HDU 3642 扫描线(立方体体积并)
Get The Treasury
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2190 Accepted Submission(s): 669
Jack can’t get the total volume of the treasury because these regions don’t always contain treasury. Through years of experience, he discovers that if a region is detected that may have treasury at more than two different spots, the region really exist treasure. And now Jack only wants to know the minimum volume of the treasury.
Now Jack entrusts the problem to you.
Each test case is given in some lines. In the first line there is an integer n (1 ≤ n ≤ 1000), the number of spots on the surface of the earth that he had detected. Then n lines follow, every line contains six integers x1, y1, z1, x2, y2 and z2, separated by a space. The absolute value of x and y coordinates of the vertices is no more than 106, and that of z coordinate is no more than 500.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 1005
#define ll root<<1
#define rr root<<1|1
#define mid (a[root].l+a[root].r)/2 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} struct node{
int l, r;
int one, two, more;
int val;
}a[N*]; struct Line{
int x1, x2, y, val;
Line(){}
Line(int a,int b,int c,int d){
x1=a;
x2=b;
y=c;
val=d;
}
}line[N*]; bool cmp(Line a,Line b){
return a.y<b.y;
} struct spot{
int x1, y1, z1, x2, y2, z2;
}s[N]; int n, nx, nz;
int xx[N*];
int zz[N*]; int b_s(int key){
int l=, r=nx-;
while(l<=r){
int mm=(l+r)/;
if(xx[mm]==key) return mm;
else if(xx[mm]>key) r=mm-;
else if(xx[mm]<key) l=mm+;
}
} void build(int l,int r,int root){
a[root].l=l;
a[root].r=r;
a[root].one=a[root].two=a[root].more=a[root].val=;
if(l==r) return;
build(l,mid,ll);
build(mid+,r,rr);
} void up(int root){
if(a[root].val>) a[root].one=a[root].two=a[root].more=xx[a[root].r+]-xx[a[root].l];
else if(a[root].val==){
a[root].one=a[root].two=xx[a[root].r+]-xx[a[root].l];
if(a[root].l==a[root].r) a[root].more=;
else a[root].more=a[ll].one+a[rr].one;
}
else if(a[root].val==){
a[root].one=xx[a[root].r+]-xx[a[root].l];
if(a[root].l==a[root].r) a[root].two=a[root].more=;
else{
a[root].two=a[ll].one+a[rr].one;
a[root].more=a[ll].two+a[rr].two;
}
}
else{
if(a[root].l==a[root].r) a[root].one=a[root].two=a[root].more=;
else{
a[root].one=a[ll].one+a[rr].one;
a[root].two=a[ll].two+a[rr].two;
a[root].more=a[ll].more+a[rr].more;
}
}
} void update(int l,int r,int val,int root){
if(a[root].l==l&&a[root].r==r){
a[root].val+=val;
up(root);
return;
}
if(r<=a[ll].r) update(l,r,val,ll);
else if(l>=a[rr].l) update(l,r,val,rr);
else{
update(l,mid,val,ll);
update(mid+,r,val,rr);
}
up(root);
} main()
{
int t, i, j, k;
int kase=;
cin>>t;
while(t--){
scanf("%d",&n);
nx=nz=;
for(i=;i<n;i++){
scanf("%d %d %d %d %d %d",&s[i].x1,&s[i].y1,&s[i].z1,&s[i].x2,&s[i].y2,&s[i].z2);
xx[nx++]=s[i].x1;
xx[nx++]=s[i].x2;
zz[nz++]=s[i].z1;
zz[nz++]=s[i].z2;
}
sort(xx,xx+nx);
sort(zz,zz+nz);
nx=unique(xx,xx+nx)-xx;
nz=unique(zz,zz+nz)-zz;
__int64 ans=;
for(i=;i<nz;i++){
k=;
for(j=;j<n;j++){
if(s[j].z1<=zz[i-]&&s[j].z2>=zz[i]){
line[k++]=Line(s[j].x1,s[j].x2,s[j].y1,);
line[k++]=Line(s[j].x1,s[j].x2,s[j].y2,-);
}
}
sort(line,line+k,cmp);
build(,nx,);
__int64 num=;
for(j=;j<k-;j++){
update(b_s(line[j].x1),b_s(line[j].x2)-,line[j].val,);
num+=(__int64)a[].more*(__int64)(line[j+].y-line[j].y);
}
ans+=num*(__int64)(zz[i]-zz[i-]);
}
printf("Case %d: %I64d\n",kase++,ans);
}
}
HDU 3642 扫描线(立方体体积并)的更多相关文章
- HDU 3255 扫描线(立方体体积并变形)
Farming Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...
- Get The Treasury HDU - 3642(体积扫描线)
给出n个立方体,要你求这些立方体至少被覆盖三次的部分. 先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z, 然后对于每一段Z的区域内,在当 ...
- Get The Treasury HDU - 3642(扫描线求三维面积交。。体积交)
题意: ...就是求体积交... 解析: 把每一层z抽出来,计算面积交, 然后加起来即可..! 去看一下 二维面积交的代码 再看看这个三维面积交的代码.. down函数里 你发现了什么规律!!! 参考 ...
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- hdu 3642 Get The Treasury (三维的扫描线)
题目大意: 给出N个立方体. 求一个三维空间中被包围三次的空间的体积之和. 思路分析: 发现Z的范围非常小.那么我们能够枚举Z轴,然后对 x y做扫描线. 并且不用枚举全部的Z ,仅仅须要将Z离散化之 ...
- hdu 3642 覆盖3次以上体积
http://www.cnblogs.com/kane0526/archive/2013/03/06/2947118.html 题目大意:给你n个立方体,求相交区域大于等于三次的体积和. 这题需要前面 ...
- HDU 3642 Get The Treasury (线段树扫描线)
题意:给你一些长方体,问你覆盖三次及以上的体积有多大 首先我们观察x轴y轴一样很大,但是z轴很小,所以我们可以枚举z轴(-500,500),注意我们枚举的是每一段长度为一的z轴的xy轴的面积而不是点. ...
随机推荐
- 04 SQL是关于集合的
面向集合去思考 要想成为写SQL语句的高级专家, 最困难的是一个转变就是从面相过程的思维方式转变到面相集合的思维方式. 首先要停止那些一次处理一行数据的过程化步骤思维, 试着把思路转移到使用类似于 “ ...
- jQuery动态加载css文件实现方法
$("<link>").attr({ rel: "stylesheet",type: "text/css",href: &quo ...
- 深入浅出RxJava(一:基础篇)
RxJava正在Android开发者中变的越来越流行.唯一的问题就是上手不容易,尤其是大部分人之前都是使用命令式编程语言.但是一旦你弄明白了,你就会发现RxJava真是太棒了. 这里仅仅是帮助你了解R ...
- 从linux系统mysql导出数据库
原文:http://blog.csdn.net/lifuxiangcaohui/article/details/50763674 1.MySQL数据库导出 /usr/local/mysql/bin/m ...
- python和shell变量互相传递的几种方法
python -> shell: 1.环境变量 复制代码代码如下: import os var=123或var='123'os.environ['var']=str(var) #enviro ...
- Ajax 完整教程 (转)
http://www.cnblogs.com/Garden-blog/archive/2011/03/11/1981778.html
- php学习注意点
1 多阅读手册和源代码 没什么比阅读手册更值得强调的事了–仅仅通过阅读手册你就可以学习到很多东西,特别是很多有关于字符串和数组的函数.就在这些函数里面包括许多有用的功能,如果你仔细阅读手册,你会经常发 ...
- Python装饰模式实现源码分享
1.一般来说,通过继承可以获得父类的属性,还可以通过重载修改其方法. 2.装饰模式可以不以继承的方式而动态地修改类的方法. 3.装饰模式可以不以继承的方式而返回一个被修改的类. 4.基本实现 程序演示 ...
- Hive优化
hive.optimize.cp=true:列裁剪hive.optimize.prunner:分区裁剪hive.limit.optimize.enable=true:优化LIMIT n语句hive.l ...
- 腾讯云centos 7部署 dotnetcore+Angular2 实践
版权声明:本文由屈政斌原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/239 来源:腾云阁 https://www.qclo ...