链接

刚开始看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. linux应用之mysql数据库的安装及配置(centos)

    CentOS下Mysql数据库的安装与配置   如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.eclipse的安装(这个在之前的一篇随笔中已经有详细讲 ...

  2. android:textAppearance

    Android之系统自带的文字外观设置及实际显示效果图 android:textAppearancexml布局里面设置文字的外观: 如“android:textAppearance=“?android ...

  3. codeforces 664B B. Rebus(乱搞题)

    题目链接: B. Rebus time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Linux服务:使用Supervisor管理进程

    一.简介 由于基本每个公司都会用到supervisor这个进程管理工具,这里简单阐述一下. Supervisor (http://supervisord.org) 是一个用Python写Linux下的 ...

  5. mac上Firefox安装firebug和firepath

    Firefox安装Selenium ide插件时提示:该附加组件无法安装 因为它似乎已损坏,如下图: 此时千万不要去想着这个插件有问题,可能是Firefox的版本问题. 在Firefox45之后的新版 ...

  6. linux 中的局部变量、全局变量、shell 变量的总结

    系统局部变量和全局变量  一.变量分类局部变量和环境变量,局部变量只适用于当前shell,而环境变量是全局的,它适用于所有当前shell以及其派生出来的任意子进程,有些变量是用户创建的,其他的则是专用 ...

  7. vue render函数使用jsx语法 可以使用v-model语法 vuex实现数据持久化

    render函数使用jsx语法: 安装插件  transform-vue-jsx 可以使用v-model语法安装插件 jsx-v-model .babelrc文件配置: vuex实现数据持久化 安装插 ...

  8. office2007下载地址

    thunder://QUFodHRwOi8vNDYuZHVvdGUub3JnOjgwODAvb2ZmaWNlMjAwN3Byby56aXBaWg==thunder://QUFodHRwOi8vNTEu ...

  9. [poj2186]Popular Cows(targin缩点)

    题意:求其他所有牛都认为其牛的牛的个数. 解题关键:targin算法模板题,缩点形成一棵树,并不一定是棵树,可能含有多个入度为0的点,寻找出度为0的点(缩点之后的点)的个数,如果个数大于0,则无解,否 ...

  10. docker的安装与卸载

    卸载老版本docker sudo apt-get remove docker docker-engine docker.io /var/lib/docker/目录下存放着 images, contai ...