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. Power Stations HDU - 3663

    我为什么T了.... Power Stations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  2. codeforces1096G Lucky Tickets

    题目链接:https://codeforces.com/problemset/problem/1096/G 大意:给出\(k\)个数码\(d_1,d_2,\cdots,d_k\),构造一个由这\(k\ ...

  3. 【CTSC2017】【BZOJ4903】吉夫特 卢卡斯定理 DP

    题目描述 给你一个长度为\(n\)的数列\(a\),求有多少个长度\(\geq 2\)的不上升子序列\(a_{b_1},a_{b_2},\ldots,a_{b_k}\)满足 \[ \prod_{i=2 ...

  4. wstngfw 初始化的一些配置

    wstngfw 初始化的一些配置 1. 引导界面 2. 命令行菜单界面 3. Assign Interfaces (分配接口) Should VLANs be set up now [y|n]? nW ...

  5. Haproxy 优化

    Haproxy 自身健康检查vi /usr/local/haproxy/sbin/check_haproxy.sh #!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/b ...

  6. LOJ2557. 「CTSC2018」组合数问题

    LOJ2557. 「CTSC2018」组合数问题 这道题是我第一道自己做完的题答题.考场上面我只拿了41分,完全没有经验.现在才发现其实掌握了大概的思路还是不难. 首先模拟退火,通过了1,2,6,9, ...

  7. springboot jar包运行中获取资源文件

    1. 今天晚上写了一个程序,基于Spring boot的一个小网站,发现使用FileUtils.class.getResource(path)来获取jar包中的资源文件并不能成功,其路径很奇怪 fil ...

  8. 关于python的GIL全局解释器锁的简单理解

    GIL是解释器内部的一把锁,确切一点说是CPython解释器内部的一把锁,所以要注意区分 这和我们在Python代码中使用线程锁Lock并不是一个层面的概念. 1. GIL产生的背景: 在CPytho ...

  9. 第一次有人把5G讲的这么简单明了

    第一次有人把5G讲的这么简单明了 鲜枣课堂 纯洁的微笑 今天 关于5G通信,常见的文章都讲的晦涩难懂,不忍往下看,特转载一篇,用大白话实现5G入门. 简单说,5G就是第五代通信技术,主要特点是波长为毫 ...

  10. JavaScript深入之从原型到原型链

    构造函数创建对象 我们先使用构造函数创建一个对象: function Person(){} var person = new Person(); person.name = 'Kevin'; cons ...