HDU 3642 求体积交集
Get The Treasury
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=3642
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
题意
给你一些立方体,求相交三次或以上的体积和。
题解
昨天做了个求面积交两次或以上的,今天升级了,交三次其实还好,和交两次超不多,但是球体积我就有点懵了,想了好久,不知道咋办。
最终看题解,结果。。。感觉这不是暴力吗?多出来的一维z,先把z排序,然后每次把包含z[i]到z[i+1]的立方体加入到一个零食队列中,求这些立方体的面积并,在乘上(z[i+1]-z[i])。
既然这样可以过,那其实和二维没什么差别了,无非就是代码多了一些,都是套路啊!
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x7f7f7f7f
#define N 1050
ll kthx[N<<1],kthz[N<<1];
template<typename T>void read(T&x)
{
ll k=0; char c=getchar();
x=0;
while(!isdigit(c)&&c!=EOF)k^=c=='-',c=getchar();
if (c==EOF)exit(0);
while(isdigit(c))x=x*10+c-'0',c=getchar();
x=k?-x:x;
}
struct Query
{
ll l,r,z1,z2,h; int id;
bool operator<(const Query&e)const
{return h<e.h;}
}que[N<<1],tmp[N<<1];
struct Node{int l,r,lazy;ll sum,sum2,sum3;};
struct segmentTree
{
Node tr[N<<3];
void push_up(int x);
void bt(int x,int l,int r);
void update(int x,int l,int r,int tt);
}seg;
void segmentTree::push_up(int x)
{
ll len=kthx[tr[x].r+1]-kthx[tr[x].l];
tr[x].sum=0;
if (tr[x].l<tr[x].r)tr[x].sum=tr[x<<1].sum+tr[x<<1|1].sum;
if (tr[x].lazy>=1)tr[x].sum=len;
tr[x].sum2=0;
if (tr[x].lazy>=2)tr[x].sum2=len;
if (tr[x].l<tr[x].r&&tr[x].lazy==1)tr[x].sum2=tr[x<<1].sum+tr[x<<1|1].sum;
if (tr[x].l<tr[x].r&&tr[x].lazy==0)tr[x].sum2=tr[x<<1].sum2+tr[x<<1|1].sum2;
tr[x].sum3=0;
if (tr[x].lazy>=3)tr[x].sum3=len;
if (tr[x].l==tr[x].r)return;
if (tr[x].lazy==2)tr[x].sum3=tr[x<<1].sum+tr[x<<1|1].sum;
if (tr[x].lazy==1)tr[x].sum3=tr[x<<1].sum2+tr[x<<1|1].sum2;
if (tr[x].lazy==0)tr[x].sum3=tr[x<<1].sum3+tr[x<<1|1].sum3;
}
void segmentTree::bt(int x,int l,int r)
{
tr[x]=Node{l,r,0,0,0,0};
if(l==r)return;
int mid=(l+r)>>1;
bt(x<<1,l,mid);
bt(x<<1|1,mid+1,r);
}
void segmentTree::update(int x,int l,int r,int tt)
{
if (l<=tr[x].l&&tr[x].r<=r)
{
tr[x].lazy+=tt;
push_up(x);
return;
}
int mid=(tr[x].l+tr[x].r)>>1;
if(l<=mid)update(x<<1,l,r,tt);
if(mid<r)update(x<<1|1,l,r,tt);
push_up(x);
}
void work()
{
int m,numx=0,numz=0;
ll ans=0;
read(m);
for(int i=1;i<=m;i++)
{
ll x1,y1,z1,x2,y2,z2;
//scanf("%lld%lld%lld%lld%lld%lld",&x1,&y1,&z1,&x2,&y2,&z2);
read(x1); read(y1); read(z1); read(x2); read(y2); read(z2);
que[i]={x1,x2,z1,z2,y1,1};
que[i+m]={x1,x2,z1,z2,y2,-1};
kthx[++numx]=x1;
kthx[++numx]=x2;
kthz[++numz]=z1;
kthz[++numz]=z2;
}
sort(que+1,que+numx+1);
sort(kthx+1,kthx+numx+1);
sort(kthz+1,kthz+numz+1);
numx=unique(kthx+1,kthx+numx+1)-kthx-1;
numz=unique(kthz+1,kthz+numz+1)-kthz-1;
for(int i=1;i<=2*m;i++)
{
que[i].l=lower_bound(kthx+1,kthx+numx+1,que[i].l)-kthx;
que[i].r=lower_bound(kthx+1,kthx+numx+1,que[i].r)-kthx-1;
}
seg.bt(1,1,numx);
for(int j=1;j<=numz-1;j++)
{
ll z1=kthz[j],z2=kthz[j+1],tp=0,now=0;
for(int i=1;i<=2*m;i++)
if (que[i].z1<=z1&&z2<=que[i].z2)tmp[++now]=que[i];
for(int i=1;i<=now;i++)
{
seg.update(1,tmp[i].l,tmp[i].r,tmp[i].id);
tp+=seg.tr[1].sum3*(tmp[i+1].h-tmp[i].h);
}
ans+=1LL*tp*(z2-z1);
}
static int cas;
printf("Case %d: %lld\n",++cas,ans);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("aa.in","r",stdin);
#endif
int T;
read(T);
while(T--)work();
}
HDU 3642 求体积交集的更多相关文章
- hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- Q - Get The Treasury - HDU 3642 (扫面线求体积)
题意:求被三个或三个以上立方体重合的体积 分析:就是平面面积的加强,不过归根还是一样的,可以把z轴按照从小向大分区间N个,然后可以得到N个平面,用平面重复三次以上的在和高度计算体积. ******** ...
- HDU - 3642 Get The Treasury(线段树求体积交)
https://cn.vjudge.net/problem/HDU-3642 题意 求立方体相交至少3次的体积. 分析 三维的呢..首先解决至少覆盖三次的问题.则用三个标记,更新时的细节要注意. 注意 ...
- hdu 3642 Get The Treasury
Get The Treasury http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Othe ...
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- Get The Treasury HDU - 3642(扫描线求三维面积交。。体积交)
题意: ...就是求体积交... 解析: 把每一层z抽出来,计算面积交, 然后加起来即可..! 去看一下 二维面积交的代码 再看看这个三维面积交的代码.. down函数里 你发现了什么规律!!! 参考 ...
- 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轴的面积而不是点. ...
随机推荐
- RX232串口发送
在进行工程调试的时候有时候需要对变量进行观察,SingnaTap II Logic Analyzer 只能对管脚进行观察,所以要观察内部的变量必须把内部的变量进行输出.一种方法是直接把变量定义成管脚通 ...
- 第2组 Alpha冲刺(3/4)
17-材料-黄智(252342126) 22:10:46 队名:十一个憨批 组长博客 作业博客 组长黄智 过去两天完成的任务:写博客,复习C语言 GitHub签入记录 接下来的计划:构思游戏实现 还剩 ...
- (转)实验文档2:实战交付一套dubbo微服务到kubernetes集群
基础架构 主机名 角色 ip HDSS7-11.host.com k8s代理节点1,zk1 10.4.7.11 HDSS7-12.host.com k8s代理节点2,zk2 10.4.7.12 HDS ...
- element-ui中el-table表格的使用(如何取到当前列的所有数据)
基本使用都不多说了, 我们知道这个表格组件,每个单元格内容是table绑定的data中的某个属性决定的,但是如果我们想根据这个属性值,渲染出另一个值呢,首先问题来了,我如何获得当前列的值, 查了查,我 ...
- js和jQuery实现的Ajax
1. JS实现Ajax <!doctype html> <html lang="en"> <head> <meta charset=&qu ...
- msql数据库常用指令操作
数据库指令 1.数据库指令 创建数据库:create database db_name; 删除数据库:drop database db_name; 显示数据库:show databases: 导出数据 ...
- MATLAB实现模糊控制
一.简介 MATLAB软件有提供一个模糊推理系统编辑器,利用模糊工具箱在matlab命令窗口输入Fuzzy命令进入模糊控制编辑环境 二.主要步骤 1.接受输入变量 2.输入变量模糊化 3.利用模糊规则 ...
- 利用csv文件批量编辑更新sql
历史表(popularity_ranking)数据中只存了用户手机号,业务需求中需要新增用户昵称字段, 这里我们用户表和popularity_ranking表在不同数据库中,有两种方法:1.编写后台服 ...
- 执行git pull时提示Connection reset by 13.229.188.59 port 22
问题如下图: 解决办法: 1. 2. 3. 4. 5. 6.
- Android开发final的用法
Android开发final的用法 final如果修饰类,该类不能被继承: final如果修饰变量,该变量不能被修改,不能再重新赋值,即变为常量: final如果修饰方法,该方法不能被重写: 此外 ...