链接

刚开始看n挺小,以为是二维的线段树,想了一会也没想到怎么解,之后看到z值非常小,想到可以直接枚举z,确定一个坐标,然后把三维转化为二维,把体积转化为面。

枚举z从-500到500,然后用面积并的解法求出单位z坐标上满足题意的面积。

把1写成了L,查错查了好久。其余还好,1A。

求覆盖超过两次的面积,up更新上的写法如下:

void up(int w,int l,int r)
{
if(fs[w]>)
{
s[w][] = s[w][] = s[w][] = val[r+] - val[l];
}
else if(fs[w]>)
{
s[w][] = s[w][] = val[r+]-val[l];
if(l==r)
s[w][] = ;
else s[w][] = s[w<<][]+s[w<<|][];
}
else if(fs[w])
{
s[w][] = val[r+]-val[l];
if(l==r)
s[w][] = s[w][] = ;
else
{
s[w][] = s[w<<][]+s[w<<|][];
s[w][] =s[w<<][]+s[w<<|][];
}
}
else
{
if(l==r)
s[w][] = s[w][] = s[w][] = ;
else
{
s[w][] = s[w<<][]+s[w<<|][];
s[w][] = s[w<<][]+s[w<<|][];
s[w][] = s[w<<][]+s[w<<|][];
}
}
}

代码:

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define N 2010
#define LL __int64
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
map<int,int>f;
struct node
{
int x1,x2,y,f;
int z1,z2;
node(){}
node(int x1,int x2,int y,int f,int z1,int z2):x1(x1),x2(x2),y(y),f(f),z1(z1),z2(z2){}
bool operator < (const node &S) const
{
return y<S.y;
}
}p[N],q[N];
int a[N],val[N];
int s[N<<][],fs[N<<];
void up(int w,int l,int r)
{
if(fs[w]>)
{
s[w][] = s[w][] = s[w][] = val[r+] - val[l];
}
else if(fs[w]>)
{
s[w][] = s[w][] = val[r+]-val[l];
if(l==r)
s[w][] = ;
else s[w][] = s[w<<][]+s[w<<|][];
}
else if(fs[w])
{
s[w][] = val[r+]-val[l];
if(l==r)
s[w][] = s[w][] = ;
else
{
s[w][] = s[w<<][]+s[w<<|][];
s[w][] =s[w<<][]+s[w<<|][];
}
}
else
{
if(l==r)
s[w][] = s[w][] = s[w][] = ;
else
{
s[w][] = s[w<<][]+s[w<<|][];
s[w][] = s[w<<][]+s[w<<|][];
s[w][] = s[w<<][]+s[w<<|][];
}
}
}
void build(int l,int r,int w)
{
s[w][] = s[w][] = s[w][] = ;
fs[w] = ;
if(l==r)
return ;
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
up(w,l,r);
}
void update(int a,int b,int d,int l,int r,int w)
{
// cout<<l<<" "<<r<<" "<<w<<endl;
if(a<=l&&b>=r)
{
fs[w]+=d;
//cout<<l<<" "<<r<<" "<<fs[w]<<" "<<w<<endl;
up(w,l,r);
return ;
}
int m = (l+r)>>;
if(a<=m) update(a,b,d,l,m,w<<);
if(b>m) update(a,b,d,m+,r,w<<|);
up(w,l,r);
}
int main()
{
int n,i,j;
int t,kk=;
cin>>t;
while(t--)
{
scanf("%d",&n);
f.clear();
int g = ;
for(i = ;i <= n; i++)
{
int x1,x2,y1,y2,z1,z2;
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
p[++g] = node(x1,x2,y1,,z1,z2);
a[g] = x1;
p[++g] = node(x1,x2,y2,-,z1,z2);
a[g] = x2;
}
sort(a+,a+g+);
sort(p+,p+g+);
int o = ;
f[a[]] = ++o;
val[] = a[];
for(i = ; i <= g; i++)
if(a[i]!=a[i-])
{
f[a[i]] = ++o;
val[o] = a[i];
}
LL ans = ;
for(i = - ; i < ; i++)
{
int e = ;
build(,o-,);
for(j = ; j <= g ;j++)
{
if(p[j].z1>i||p[j].z1>i+||i>p[j].z2||p[j].z2<i+)
continue;
q[++e] = p[j];
}
for(j = ; j < e; j++)
{
int l = f[q[j].x1];
int r = f[q[j].x2]-;
// cout<<q[i].f<<" "<<i<<endl;
if(l<=r)
{
update(l,r,q[j].f,,o-,);
}
LL sum = (LL)(q[j+].y-q[j].y)*s[][];
//cout<<sum<<" ."<<i<<" "<<s[1][2]<<endl;
ans+=sum;
}
}
printf("Case %d: %I64d\n",++kk,ans);
}
return ;
}

hdu3642Get The Treasury的更多相关文章

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

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

  2. hdu 3642 Get The Treasury

    Get The Treasury http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Othe ...

  3. hdu3642 Get The Treasury 线段树--扫描线

    Jack knows that there is a great underground treasury in a secret region. And he has a special devic ...

  4. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  5. luogu P1623 [CEOI2007]树的匹配Treasury

    题目链接 luogu P1623 [CEOI2007]树的匹配Treasury 题解 f[i][0/1]表示当前位置没用/用了 转移暴力就可以了 code // luogu-judger-enable ...

  6. HDU3642 Get The Treasury —— 求矩形交体积 线段树 + 扫描线 + 离散化

    题目链接:https://vjudge.net/problem/HDU-3642 Jack knows that there is a great underground treasury in a ...

  7. HDU 3642 Get The Treasury (线段树扫描线)

    题意:给你一些长方体,问你覆盖三次及以上的体积有多大 首先我们观察x轴y轴一样很大,但是z轴很小,所以我们可以枚举z轴(-500,500),注意我们枚举的是每一段长度为一的z轴的xy轴的面积而不是点. ...

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

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

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

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

随机推荐

  1. PHP截取中英文混合字符

    <?php //////////////////////////////////////////////////////////////////// // PHP截取中英文及标点符号混合的字符串 ...

  2. php排序方法之快速排序

    $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function quickSort($arr){ if (count($arr) <= 1){ retu ...

  3. windows查看与清理dns缓存

    1.windows下在命令行输入  ipconfig /flushdns 清理本地dns缓存查看dns缓存   ipconfig/displaydns2.Mac OSX下在命令行输入  lookupd ...

  4. rsync(六)命令中文手册

    rsync(1) rsync(1) 名称 rsync - 一个快速.多功能的远程(和本地)文件拷贝工具 摘要 Local: rsync [OPTION...] SRC... [DEST] Access ...

  5. 九、myeclipse开发背景保护色设置

    window->preferences->Editors->Text Editors->Background color 背景颜色向你推荐: 色调:85.饱和度:1 2 3.亮 ...

  6. Apple Tree

    题意: 给一有根树,每个叶子上有一些苹果,现在要求你拿掉一些苹果,使得每一个点的 儿子的子树内的苹果数相同. 解法: 首先可以发现$cnt$个叶子节点之间的关系可以用$cnt-1$个独立方程表示出来. ...

  7. A - Toy Cars

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Little ...

  8. 徒手撸一个 Spring Boot 中的 Starter ,解密自动化配置黑魔法!

    我们使用 Spring Boot,基本上都是沉醉在它 Stater 的方便之中.Starter 为我们带来了众多的自动化配置,有了这些自动化配置,我们可以不费吹灰之力就能搭建一个生产级开发环境,有的小 ...

  9. iTween基础之iTweenPath浅析(自定义路径移动)

    http://www.2cto.com/kf/201604/498023.html 在游戏开发中经常会用到让一个游戏对象按照指定的路线移动,iTweenPath就提供了可视化的编辑路径功能. iTwe ...

  10. 渲染路径-u3d渲染路径比较

    Unity支持不同的渲染路径.应具体取决于你的游戏内容和目标平台/硬件来选择使用哪一个.不同的渲染路径有不同的特点和性能特点,主要影响灯光和阴影.        项目所使用的渲染路径在Player S ...