Get The Treasury

http://acm.hdu.edu.cn/showproblem.php?pid=3642

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
Jack knows that there is a great underground treasury
in a secret region. And he has a special device that can be used to detect
treasury under the surface of the earth. One day he got outside with the device
to ascertain the treasury. He chose many different locations on the surface of
the earth near the secret region. And at each spot he used the device to detect
treasury and got some data from it representing a region, which may contain
treasury below the surface. The data from the device at each spot is six
integers x1, y1, z1, x2,
y2 and z2 (x1<x2,
y1<y2, z1<z2). According to
the instruction of the device they represent the range of x, y and z coordinates
of the region. That is to say, the x coordinate of the region, which may contain
treasury, ranges from x1 to x2. So do y and z coordinates.
The origin of the coordinates is a fixed point under the ground.
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.

 
Input
The first line of the input file contains a single
integer t, the number of test cases, followed by the input data for each test
case.
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.

 
Output
For each test case, you should output “Case a: b” in a
single line. a is the case number, and b is the minimum volume of treasury. The
case number is counted from one.
 
Sample Input
2
1
0 0 0 5 6 4
3
0 0 0 5 5 5
3 3 3 9 10 11
3 3 3 13 20 45
 
Sample Output
Case 1: 0
Case 2: 8
 
Source
 
Recommend
lcy   |   We have carefully selected several similar
problems for you:  2871 3308 3641 3397 1540 
 
题意:求n个长方体至少相交3次的体积和
z这一维只有500,所以枚举z轴,然后就相当于二维的扫描线
线段树维护区间完全覆盖1、2、3次的长度
 
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define N 1001
#define lc k<<1,l,mid
#define rc k<<1|1,mid+1,r
struct node
{
int l,r,h,f;
bool operator < (node p)const
{
return h<p.h;
}
}a[N<<];
struct edge
{
int x,xx,y,yy,z,zz;
}b[N];
int sum1[N<<],sum2[N<<],sum3[N<<],f[N<<],has[N<<],has2[N<<];
long long ans;
int n,cnt,opl,opr,w;
void up(int k,int l,int r)
{
if(f[k]>=) sum3[k]=has2[r+]-has2[l];
else if(f[k]==)
{
sum3[k]=sum1[k<<]+sum1[k<<|];
sum2[k]=has2[r+]-has2[l];
}
else if(f[k]==)
{
sum3[k]=sum2[k<<]+sum2[k<<|];
sum2[k]=sum1[k<<]+sum1[k<<|];
sum1[k]=has2[r+]-has2[l];
}
else
{
sum3[k]=sum3[k<<]+sum3[k<<|];
sum2[k]=sum2[k<<]+sum2[k<<|];
sum1[k]=sum1[k<<]+sum1[k<<|];
}
}
void change(int k,int l,int r)
{
if(opl<=l && r<=opr)
{
f[k]+=w;
up(k,l,r);
return;
}
int mid=l+r>>;
if(opl<=mid) change(lc);
if(opr>mid) change(rc);
up(k,l,r);
}
int main()
{
int T;
scanf("%d",&T);
for(int t=;t<=T;t++)
{
ans=;
cnt=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d%d%d%d%d",&b[i].x,&b[i].y,&b[i].z,&b[i].xx,&b[i].yy,&b[i].zz);
has[i*-]=b[i].z; has[i*]=b[i].zz;
}
sort(has+,has+*n+);
cnt=unique(has+,has+*n+)-(has+);
for(int i=;i<cnt;i++)
{
int sz=;
for(int j=;j<=n;j++)
if(b[j].z<=has[i] && b[j].zz>=has[i+])
{
a[++sz].l=b[j].x; a[sz].r=b[j].xx; a[sz].h=b[j].y; a[sz].f=;
a[++sz].l=b[j].x; a[sz].r=b[j].xx; a[sz].h=b[j].yy; a[sz].f=-;
has2[sz-]=b[j].x; has2[sz]=b[j].xx;
}
sort(has2+,has2+sz+);
int m=unique(has2+,has2+sz+)-(has2+);
sort(a+,a+sz+);
memset(sum1,,sizeof(sum1));
memset(sum2,,sizeof(sum2));
memset(sum3,,sizeof(sum3));
for(int j=;j<=sz;j++)
{
opl=lower_bound(has2+,has2+m+,a[j].l)-has2;
opr=lower_bound(has2+,has2+m+,a[j].r)-has2-;
w=a[j].f;
change(,,m);
ans+=1ll*sum3[]*(a[j+].h-a[j].h)*(has[i+]-has[i]);
}
}
printf("Case %d: %I64d\n",t,ans);
}
}
 

hdu 3642 Get The Treasury的更多相关文章

  1. hdu 3642 Get The Treasury(扫描线)

    pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...

  2. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  3. HDU 3642 Get The Treasury (线段树扫描线)

    题意:给你一些长方体,问你覆盖三次及以上的体积有多大 首先我们观察x轴y轴一样很大,但是z轴很小,所以我们可以枚举z轴(-500,500),注意我们枚举的是每一段长度为一的z轴的xy轴的面积而不是点. ...

  4. HDU 3642 Get The Treasury (线段树扫描线,求体积并)

    参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...

  5. HDU 3642 Get The Treasury 线段树+分层扫描线

    http://www.acmerblog.com/hdu-3642-get-the-treasury-6603.html 学习:三维就是把竖坐标离散化分层,每一层进行线段树二维面积并就好了

  6. hdu 3642 Get The Treasury (三维的扫描线)

    题目大意: 给出N个立方体. 求一个三维空间中被包围三次的空间的体积之和. 思路分析: 发现Z的范围非常小.那么我们能够枚举Z轴,然后对 x y做扫描线. 并且不用枚举全部的Z ,仅仅须要将Z离散化之 ...

  7. HDU - 3642 Get The Treasury(线段树求体积交)

    https://cn.vjudge.net/problem/HDU-3642 题意 求立方体相交至少3次的体积. 分析 三维的呢..首先解决至少覆盖三次的问题.则用三个标记,更新时的细节要注意. 注意 ...

  8. HDU 3642 Get The Treasury ( 线段树 求长方体体积并 )

    求覆盖三次及其以上的长方体体积并. 这题跟 http://wenku.baidu.com/view/d6f309eb81c758f5f61f6722.html 这里讲的长方体体积并并不一样. 因为本题 ...

  9. Q - Get The Treasury - HDU 3642 (扫面线求体积)

    题意:求被三个或三个以上立方体重合的体积 分析:就是平面面积的加强,不过归根还是一样的,可以把z轴按照从小向大分区间N个,然后可以得到N个平面,用平面重复三次以上的在和高度计算体积. ******** ...

随机推荐

  1. 【learning】凸包

    吐槽 计算几何这种东西qwq一开始真的觉得恶心qwq(主要是总觉得为啥画图那么直观的东西非要写一大堆式子来求qwq真的难受qwq) 但其实静下心来学习的话感觉还是很妙的ovo题目思考起来也十分好玩ov ...

  2. SpringBoot初探之Swagger配置

    Swagger是一个用于描述和测试restful接口的工具,只要在定义restful接口时增加一些类和方法的描述注解,通过很简单的配置就可以得到一个展示接口定义页面,也可以在页面上设置参数提交测试接口 ...

  3. angular路由详解六(路由守卫)

    路由守卫 CanActivate: 处理导航到某个路由的情况. CanDeactivate:处理从当前路由离开的情况. Resole:在路由激活之前获取路由数据. 1.CanActivate: 处理导 ...

  4. SpringMVC入门就这么简单

    什么是SpringMVC? SpringMVC是Spring家族的一员,Spring是将现在开发中流行的组件进行组合而成的一个框架!它用在基于MVC的表现层开发,类似于struts2框架 为什么要使用 ...

  5. NancyFX 第三章 Web框架

    如果使用Nancy作为一个WEB框架而言,会有什么不同?实际上很多. 在使用Nancy框架为网页添加Rest节点和路由和之前的Rest框架中是相同的,这方面没有什么需要学习的了.Nancy采用一贯的处 ...

  6. 使用NPOI导出Excel引发异常(IsReadOnly = “book.IsReadOnly”引发了类型“System.NotImplementedException”的异常)

    前言: 本人调式npoi导入.导出试用成功后,引入到项目中,导入完美运行,但是导出怎么样都看不到现在的页面,而且浏览器和后台都没有报任务错误,让人好事纳闷,后来去调式,发现在除了一个IsReadOnl ...

  7. 线段树 (区间查询最大 区间求和 区间加)带lazy

    ; struct Segment_tree { struct Node { int val,Max,lazy; ]; void init() { lazy=son[]=son[]=Size=val=M ...

  8. python之hasattr()、 getattr() 、setattr() 函数

    这三个方法可以实现反射和内省机制,在实际项目中很常用,功能也很强大. [转]http://www.cnblogs.com/cenyu/p/5713686.html hasattr(object, na ...

  9. this->的作用

    参考:https://www.zhihu.com/question/23324143 1.来源: 当年没有C++编译器,只能通过C++转成C语言才编译.而C++中的class就被翻译C语言的struc ...

  10. eclipse热部署web项目

    一.选中JavaEE视图 因为在普通的Java视图下,窗口下方没有server选项卡 二.双击Tomcat 注意:可能很多人当然包括我一开始的时候,都是喜欢右键Tomcat然后Add and remo ...