Get The Treasury - HDU 3642 扫描线 重复三次的体积
来源:互联网 发布:厚学网网站源码 编辑:程序博客网 时间:2024/06/07 12:51
Get The Treasury
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2083 Accepted Submission(s): 640
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.
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.
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
210 0 0 5 6 430 0 0 5 5 53 3 3 9 10 113 3 3 13 20 45
Sample Output
Case 1: 0Case 2: 8
思路:因为z轴不超过500,所以要离散化z轴以后,转化成二维的来做。这样就和HDU1255差不多了。
AC代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;struct Cube{ ll x1,y1,z1,x2,y2,z2;}cubes[10100];struct node{ int l,r,lazy; ll sum[4];}tree[16010];struct node2{ int l,r,f; ll h;}line[40100];bool cmp(node2 a,node2 b){ return a.h<b.h;}int n,mx,mz;ll pz[40100],px[40100],fx[2000010];void build(int o,int l,int r){ tree[o].l=l; tree[o].r=r; tree[o].lazy=0; for(int i=1;i<=3;i++) tree[o].sum[i]=0; tree[o].sum[0]=px[tree[o].r]-px[tree[o].l-1]; if(l==r) return; int mi=(l+r)/2; build(o<<1,l,mi); build(o<<1|1,mi+1,r);}void solve(int o){ int i,j,k; if(tree[o].l==tree[o].r) { for(i=1;i<=min(tree[o].lazy,3);i++) tree[o].sum[i]=tree[o].sum[0]; for(;i<=3;i++) tree[o].sum[i]=0; return; } if(tree[o].lazy>=3) { for(i=1;i<=3;i++) tree[o].sum[i]=tree[o].sum[0]; } else if(tree[o].lazy==2) { for(i=1;i<=2;i++) tree[o].sum[i]=tree[o].sum[0]; tree[o].sum[3]=tree[o<<1].sum[1]+tree[o<<1|1].sum[1]; } else if(tree[o].lazy==1) { tree[o].sum[1]=tree[o].sum[0]; tree[o].sum[2]=tree[o<<1].sum[1]+tree[o<<1|1].sum[1]; tree[o].sum[3]=tree[o<<1].sum[2]+tree[o<<1|1].sum[2]; } else if(tree[o].lazy==0) { for(i=1;i<=3;i++) tree[o].sum[i]=tree[o<<1].sum[i]+tree[o<<1|1].sum[i]; }}void update(int o,int l,int r,int f){ if(tree[o].l==l && tree[o].r==r && tree[o].lazy+f>=0) { tree[o].lazy+=f; solve(o); return; } int mi=(tree[o].l+tree[o].r)/2; if(r<=mi) update(o<<1,l,r,f); else if(l>mi) update(o<<1|1,l,r,f); else { update(o<<1,l,mi,f); update(o<<1|1,mi+1,r,f); } solve(o);}int main(){ int T,t,i,j,k,p,z,l,r; ll ans; scanf("%d",&T); for(t=1;t<=T;t++) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&cubes[i].x1,&cubes[i].y1,&cubes[i].z1, &cubes[i].x2,&cubes[i].y2,&cubes[i].z2); cubes[i].x1+=1000000;cubes[i].x2+=1000000; pz[i*2-1]=cubes[i].z1;pz[i*2]=cubes[i].z2; px[i*2-1]=cubes[i].x1;px[i*2]=cubes[i].x2; } sort(pz+1,pz+1+n*2); sort(px+1,px+1+n*2); mx=-1;mz=-1;px[0]=-100000000;pz[0]=-100000000; for(i=1;i<=n*2;i++) { if(px[i]!=px[i-1]) { px[++mx]=px[i]; fx[px[i]]=mx; } if(pz[i]!=pz[i-1]) pz[++mz]=pz[i]; } ans=0; for(i=1;i<=mz;i++) { p=0; for(j=1;j<=n;j++) if(cubes[j].z1<pz[i] && cubes[j].z2>=pz[i]) { p+=2; l=fx[cubes[j].x1]+1;r=fx[cubes[j].x2]; line[p-1].l=l;line[p-1].r=r;line[p-1].f=1;line[p-1].h=cubes[j].y1; line[p].l=l;line[p].r=r;line[p].f=-1;line[p].h=cubes[j].y2; } sort(line+1,line+1+p,cmp); build(1,1,mx); for(j=1;j<p;j++) { update(1,line[j].l,line[j].r,line[j].f); ans+=(pz[i]-pz[i-1])*tree[1].sum[3]*(line[j+1].h-line[j].h); } } printf("Case %d: %I64d\n",t,ans); }}
0 0
- Get The Treasury - HDU 3642 扫描线 重复三次的体积
- HDU 3642 Get The Treasury(体积并+覆盖三次+线段树+扫描线)
- hdu 3642 Get The Treasury(扫描线)
- HDU 3642 Get The Treasury (线段树、扫描线求立方体体积交)
- hdu 3642 Get The Treasury 扫描线求长方体体积交
- HDU 3642 Get The Treasury (线段树扫描线进阶--求长方体重叠3次或以上的体积)
- hdu 3642 Get The Treasury (三维的扫描线)
- 扫描线 n个立方体相交区域大于等于三次的体积和 hdu3642 Get The Treasury
- Hdu 3642 Get The Treasury(长方体的体积交)
- HDU 3642——Get The Treasury(线段树+扫描线+离散化+体积交多次)
- hdu 3642 Get The Treasury(扫描线、立方体交)
- HDU 3642 Get The Treasury 【线段树】【扫描线】
- hdoj 3642 Get The Treasury 【线段树 扫描线 求立方体积交】
- hdu 3642 Get The Treasury(线段树求体积并)
- HDU 3642 Get The Treasury(体积并,离散化)
- 【hdu3642】Get The Treasury (立方体体积交+线段树+扫描线)
- hdu3642-Get The Treasury 线段树+扫描线+离散化 求三维体积并
- hdu 3642 Get The Treasury
- JavaScript基础学习笔记(2014.12.8)
- SAP TABLE BUFFERS
- Linux最帅版主面试题
- html 自定义标签使用实现方法
- makefile里PHONY总结
- Get The Treasury - HDU 3642 扫描线 重复三次的体积
- linux中的(),(()),[],[[]],{}的作用
- 什么时候使用NoSQL
- OpenCV 保存图片
- 全排列递归算法的实现
- display:inline、block、inline-block 的区别
- cocos2d-x 数学函数、常用宏粗整理
- Oracle自增ID实现
- ABAP动态编程之功能实现