https://cn.vjudge.net/problem/HDU-3642

题意

求立方体相交至少3次的体积。

分析

三维的呢。。首先解决至少覆盖三次的问题。则用三个标记,更新时的细节要注意。

注意到z比较小,于是枚举z一层层求,先求出在这一层的面积交,再乘上前后z的差值,就是体积了。注意离散化。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = + ;
const int maxm = + ;
const int mod = ; int n;
int z[maxn];
int y[maxn];
struct LINE{
int x;
int y1,y2;
int z1,z2;
int flag;
bool operator <(const LINE &a)const{
return x<a.x;
}
}line[maxn];
struct ND{
int l,r;
int cover;
bool f;
int one;//覆盖一次以上的长度
int two;//覆盖两次以上的长度
int more;
}tree[maxn<<];
void build(int rt,int l,int r){
tree[rt].l=y[l];
tree[rt].r=y[r];
tree[rt].cover=;
tree[rt].one=tree[rt].two=tree[rt].more=;
tree[rt].f=false;
if(l+==r){
tree[rt].f=true;
return;
}
int mid = (l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid,r);
} void cal(int rt){
if(tree[rt].cover>=){
tree[rt].more=tree[rt].r-tree[rt].l;
tree[rt].one=tree[rt].two=;
}else if(tree[rt].cover==){
if(tree[rt].f){
tree[rt].more=;
tree[rt].two=tree[rt].r-tree[rt].l;
tree[rt].one=;
}else{
tree[rt].more=tree[rt<<].one+tree[rt<<].two+tree[rt<<].more+
tree[rt<<|].one+tree[rt<<|].two+tree[rt<<|].more;
tree[rt].two=tree[rt].r-tree[rt].l-tree[rt].more;
tree[rt].one=;
}
}else if(tree[rt].cover==){
if(tree[rt].f){
tree[rt].more=;
tree[rt].two=;
tree[rt].one=tree[rt].r-tree[rt].l;
}else{
tree[rt].more=tree[rt<<].two+tree[rt<<].more+
tree[rt<<|].two+tree[rt<<|].more;
tree[rt].two=tree[rt<<].one+tree[rt<<|].one;
tree[rt].one=tree[rt].r-tree[rt].l-tree[rt].more-tree[rt].two;
}
}else{
if(tree[rt].f){
tree[rt].more=tree[rt].one=tree[rt].two=;
}else{
tree[rt].one=tree[rt<<].one+tree[rt<<|].one;
tree[rt].more=tree[rt<<].more+tree[rt<<|].more;
tree[rt].two=tree[rt<<].two+tree[rt<<|].two;
}
}
}
void update(int rt,double l,double r,int flag){
if(l==tree[rt].l&&r==tree[rt].r){
tree[rt].cover+=flag;
cal(rt);
return;
}
if(tree[rt<<].r>=r) update(rt<<,l,r,flag);
else if(l>=tree[rt<<|].l) update(rt<<|,l,r,flag);
else{
update(rt<<,l,tree[rt<<].r,flag);
update(rt<<|,tree[rt<<|].l,r,flag);
}
cal(rt);
}
LINE tmp[maxn];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int T,cas=;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int cnt=;
int x1,x2,y1,y2,z1,z2;
for(int i=;i<n;i++){
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
z[cnt]=z1;
y[cnt]=y1;
line[cnt].x=x1;
line[cnt].y1=y1;
line[cnt].y2=y2;
line[cnt].z1=z1;
line[cnt].z2=z2;
line[cnt++].flag=; z[cnt]=z2;
y[cnt]=y2;
line[cnt].x=x2;
line[cnt].y1=y1;
line[cnt].y2=y2;
line[cnt].z1=z1;
line[cnt].z2=z2;
line[cnt++].flag=-;
}
sort(y,y+cnt);
sort(line,line+cnt);
int t1=unique(y,y+cnt)-y;
build(,,t1-);
sort(z,z+cnt);
int t2=unique(z,z+cnt)-z;
ll ans=;
ll area=;
for(int i=;i<t2-;i++){
int m=;
for(int j=;j<cnt;j++){
if(line[j].z1<=z[i]&&line[j].z2>z[i])
tmp[m++]=line[j];
}
area=;
update(,tmp[].y1,tmp[].y2,tmp[].flag);
for(int j=;j<m;j++){
area+=1ll*tree[].more*(tmp[j].x-tmp[j-].x);
update(,tmp[j].y1,tmp[j].y2,tmp[j].flag);
}
ans+=area*(z[i+]-z[i]);
}
printf("Case %d: %lld\n",cas++,ans);
}
return ;
}

HDU - 3642 Get The Treasury(线段树求体积交)的更多相关文章

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

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

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

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

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

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

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

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

  5. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  6. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  7. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  8. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

  9. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

随机推荐

  1. 【转】RO段、RW段和ZI段 --Image$$??$$Limit 含义(zz)

    @2019-02-14 [小记] RO段.RW段和ZI段 --Image$$??$$Limit 含义(zz)

  2. multiset和set

    set集合容器:实现了红黑树的平衡二叉检索树的数据结构,插入元素时,它会自动调整二叉树的排列,把元素放到适当的位置,以保证每个子树根节点键值大于左子树所有节点的键值,小于右子树所有节点的键值:另外,还 ...

  3. Navicat Premium 12 破解(MySQL、MariaDB、MongoDB、SQL Server、SQLite)

    打开注入到安装目录中的exe中 破解提示(还没好,继续看下去) 如果你安装的是中文版,选一下中文版(英文默认即可),获取一下key(名字和组织可以自定义) 打开Navicat,选择注册(第一次打开选注 ...

  4. spring5 reactive

    示例代码:https://github.com/srpraneeth/spring5-reactive 说明文档: https://coyee.com/article/12086-spring-5-r ...

  5. poj1723 SOLDIERS

    soldiers真乃神题也! 行列显然可以分开处理. 行好办,显然就是一个货仓选址问题,取中位数即可. 列呢?? ?????? 因为懒得推式子,用不了二分,我决定使用枚举大法!一算复杂度O(n^2), ...

  6. [luogu5077][Tweetuzki 爱等差数列]

    题目链接 思路 数学题 首先列出等差数列求和的式子. \[S = \frac{(n + m)(n - m + 1)}{2}(n为末项,m为首项)\] \[S * 2= (n + m)(n - m + ...

  7. PHP数组大全

    一.数组操作的基本函数 数组的键名和值 array_values($arr);获得数组的值 array_keys($arr);获得数组的键名 array_flip($arr);数组中的值与键名互换(如 ...

  8. http uri唯一标识

    URI:唯一标识并且信息资源(简单理解为:发邮件的地址,身份证号).uri包括url 比如通过查找一个uri,找到一张图片“https://timgsa.baidu.com/timg?image&am ...

  9. 漫谈php框架之中间件

    市面上常见的php框架有很多,最近因为有技术需求,所以对常见的php框架的中间件进行了一些了解.各个框架尽管在目标上对php框架的定义大同小异,但是在实现方式上却各有不同,且看下文: 定义 首先什么是 ...

  10. 数据库 价格字段 设置 decimal(8,2),价格为100W,只显示999999.99

    DECIMAL(M,D),M是数字最大位数,D是小数点右侧数字个数,整数M-D位 decimal(8,2)数值范围是 -999999.99 ~ 999999.99 1000000超过了6位,严格模式下 ...