HDU - 3642 Get The Treasury(线段树求体积交)
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(线段树求体积交)的更多相关文章
- HDU 3642 Get The Treasury 线段树+分层扫描线
http://www.acmerblog.com/hdu-3642-get-the-treasury-6603.html 学习:三维就是把竖坐标离散化分层,每一层进行线段树二维面积并就好了
- HDU 3642 Get The Treasury ( 线段树 求长方体体积并 )
求覆盖三次及其以上的长方体体积并. 这题跟 http://wenku.baidu.com/view/d6f309eb81c758f5f61f6722.html 这里讲的长方体体积并并不一样. 因为本题 ...
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
随机推荐
- 【BZOJ1022】小约翰的游戏(博弈论)
[BZOJ1022]小约翰的游戏(博弈论) 题面 BZOJ 题解 \(Anti-SG\)游戏的模板题目. #include<iostream> #include<cstdio> ...
- 工作队列.py
#对列模式图Work Queue背后的主要思想是避免立即执行资源密集型任务的时,需要等待其他任务完成.所以我们把任务安排的晚一些,我们封装一个任务到消息中并把它发送到队列,一个进程运行在后端发送并最终 ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- (一)flask-sqlalchemy的安装和配置
在使用flask-sqlalchemy之前要先了解ORM模型,什么叫做ORM模型 一.什么是ORM ORM 全拼Object-Relation Mapping. 称为对象-关系映射 主要实现模型对象到 ...
- 这些保护Spring Boot 应用的方法,你都用了吗?
这些保护Spring Boot 应用的方法,你都用了吗? 生如夏花 SpringForAll社区 今天 Spring Boot大大简化了Spring应用程序的开发.它的自动配置和启动依赖大大减少了开始 ...
- 洛谷P1399 快餐店
题意:在基环树上找一点,使得这个点到所有点的距离最大值最小.这个点可以在某条边上. 解:很容易想到找出直径然后/2对吧...这里的直径是指任意两点间最短距离的最大值. 然而我这个SB冥思苦想了半天之后 ...
- [luogu3294][背单词]
题目链接 题意 读完题目就一个感受:这出题人tm不会说人话吗.真的感觉这个题理解题意比想出正解更难. 其实题目的意思就是,给出一些单词,给这些单词编个号,然后要求其他的单词中是这个单词后缀的词都在这个 ...
- SourceInsight快捷键
下载安装与设置 https://blog.csdn.net/k346k346/article/details/77412413 常用设置总结的还是比较全面的 问题: SourceInsight4.0中 ...
- Win32-API: 终于能正常的捕获焦点事件: WM_COMMAND、BN_SETFOCUS、EN_SETFOCUS
学习和使用win32-api来写窗口程序算算也有二三年了. 以前有个需求,想捕获控件的焦点事件(SETFOCUS. KILLFOCUS),我一直认为应该捕获 WM_SETFOCUS 和 WM_KILL ...
- bat 复制文件夹,文件名递增 等操作
句尾无';' @echo off : 回显,使命令不在dos中一行一行输出 pause : 暂停,以便看到输出结果 变量 %% 与 % % : https://zhidao.baidu.com/que ...