链接

刚开始看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. 在一个form表单中根据不同按钮实现多个action事件

    <form id="writeForm" method="post"> <div class="write-btn-tj" ...

  2. 在Eclipse配置自动提示

    1.我们打开eclipse,选择菜单栏的window选项 2.点击Windows,选择下拉菜单里面的preferences选项,之后在打开的对话框的左侧找到Java选项 3.之后点击Java选项,选择 ...

  3. AC自动机-题目集合

    AC自动机-题目集合 模板 如果你想要学习AC自动机,推荐一些学习资料. 学习可以看这篇博客 http://blog.csdn.net/niushuai666/article/details/7002 ...

  4. python中通过xlwt、xlrd和xlutils操作xls

    xlwt模块用于在内存中生成一个xls/xlsx对象,增加表格数据,并把内存中的xls对象保存为本地磁盘xls文件; xlrd模块用于把本地xls文件加载到内存中,可以读取xls文件的表格数据,查询x ...

  5. 配置android-studio应用的快捷键

    http://blog.sina.com.cn/s/blog_ad64b8200102vnl4.html

  6. android jni下c文件怎么输出logcat

    #include <android/log.h> #define LOG_TAG "clog"#define LOGD(...) __android_log_print ...

  7. bzoj4455

    容斥原理+dp 首先考虑暴力做法,我们希望点和点一对一,那么自然要保存当前点集的状态,需要状压,据说要3^n,那么自然不行 考虑容斥原理,刚才一一对应的限制太强了,我们不要一一对应,只要满足边存在就行 ...

  8. 查看Spring源码的方法

    来自为知笔记(Wiz)

  9. 【网络爬虫】【java】微博爬虫(二):如何抓取HTML页面及HttpClient使用

    一.写在前面 上篇文章以网易微博爬虫为例,给出了一个很简单的微博爬虫的爬取过程,大概说明了网络爬虫其实也就这么回事,或许初次看到这个例子觉得有些复杂,不过没有关系,上篇文章给的例子只是让大家对爬虫过程 ...

  10. 【Data structure & Algorithm】把二元查找树转变成排序的双向链表

    把二元查找树转变成排序的双向链表 题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表,要求不能创建任何新节点,只调整指针指向. 比如将二元查找树 10 /       \ 6       ...