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轴的面积而不是点. ...
随机推荐
- Linux 下操作GPIO(两种方法,驱动和mmap)(转载)
目前我所知道的在Linux下操作GPIO有两种方法: 1.编写驱动,这当然要熟悉Linux下驱动的编写方法和技巧,在驱动里可以使用ioremap函数获得GPIO物理基地址指针,然后使用这个指针根据io ...
- awt组件中文乱码Intellij解决
-Dfile.encoding=GB18030 -Dfile.encoding=GB18030
- (十)makefile
一.Makefile的作用和意义(1)工程项目中c文件太多管理不方便,因此用Makefile来做项目管理,方便编译链接过程.(2)uboot和linux kernel本质上都是C语言的项目,都由很多个 ...
- BestCoder Valentine's Day Round
昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...
- The new day of my blog
今天开始了我的博客建造之旅,作为一个ACMer(虽说是弱校的),我也想象其他人一样把自己的题解和心得记录下来,一来可以和大家分享一下,二来也可以留给将来的自己作回顾,希望众大神能够给以指导指导,让我这 ...
- Poco C++——JSON解析
#include <iostream> #include "Poco/Dynamic/Var.h" #include "Poco/Dynamic/Pair.h ...
- C++——使用类
一.运算符重载 1.运算符重载 C++允许将运算符重载扩展到用户定义的类型. 要重载运算符,需使用被称为运算符函数的特殊函数形式.运算符函数的格式如下: operatorop(argument lis ...
- Bootstrap段落(正文文本)
一.Bootstrap段落特点 段落是排版中另一个重要元素之一.在Bootstrap中为文本设置了一个全局的文本样式(这里所说的文本是指正文文本): 1.全局文本字号为14px(font-size). ...
- python和shell变量互相传递的几种方法
python -> shell: 1.环境变量 复制代码代码如下: import os var=123或var='123'os.environ['var']=str(var) #enviro ...
- semantic-ui使用gulp执行build-css报错
1.执行gulp build-css报错 [09:40:49] Starting 'build-css'... Building CSS Potentially unhandled rejection ...