链接

刚开始看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. html5--5-2 绘制直线

    html5--5-2 绘制直线 学习要点 如何在HTML5文档中添加canvas元素 canvas的属性 了解canvas坐标系 了解script元素 绘制一条直线(准确的说是线段) 什么是canva ...

  2. docker中Ubuntu安装jdk1.8

    1.在宿主系统下载所需要的jdk版本的gz文件 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133 ...

  3. 动态链接库的ELF头分析

    ELF(Executable and Linking Format)用于存储Linux程序. ELF文件分三种类型: 1.目标文件(通常是.o); 2.可执行文件(我们的运行文件)   3.动态库(. ...

  4. linux安装flume及问题

    验证是否安装成功: [root@master conf]# /usr/local/src/apache-flume-1.6.0-bin/bin/flume-ng versionError: Could ...

  5. MongoDB 2.6复制集单节点部署(三)

    MongoDB在单节点中也可以做复制集,但是仅限于测试实验,最大的好处就是部署方便快速,可以随便添加新节点,节省资源.在这里我使用的是MongoDB 2.6版本进行复制集实验(但MongoDB配置文件 ...

  6. DataWindow.NET 控件 实现点击列头排序

    1.定义字段                         Boolean ib_SetSort = true;                string is_SortType = " ...

  7. win8.1安装出错解决方法之一

    1.由于没有DVD光盘,所以没有把安装文件ISO刻录,而是使用U盘制作了一个安装盘.当U盘安装盘制作好了之后,按F12,选择从U盘启动,没有反应,即选了USB启动之后,又跳回让你选择启动路径. (解决 ...

  8. Algorithm-4th part I 学习进度 (7/12)

    在cousera跟着书的原作者学习<算法>第四版.记录以下学习进度. 课后习题代码见我的GitHub 2018.09.22 : Priority Queues 使用完全二叉树实现优先队列 ...

  9. 免证书发布ipa文件真机测试

    首先设备得越狱 众所周知,在Xcode上开发的程序只能在模拟器中运行,如果要放到真机上则要花费99美金购买开发者证书iDP.这严重阻碍了我等草根开发者探索的脚步.写个小程序,同学间分享一下这个小小的愿 ...

  10. awk用法总结

    简介 awk的命名来自于他的三位创始人Alfred Aho .Peter Weinberger 和 Brian Kernighan 的姓氏的首字母. 有多种版本:New awk(nawk),GNU a ...