给出n个立方体,要你求这些立方体至少被覆盖三次的部分。

先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z,

然后对于每一段Z的区域内,在当前的区域内对xoy轴使用一次扫描线,找到当前这个区域内被覆盖三次的体积,然后每次枚举Z,每次相加,就是最后的答案。

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define first fi
#define second se
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
using namespace std; int n, m, tol, T;
struct Node {
int l, r, h, f;
bool operator < (Node a) const {
return h < a.h;
}
};
Node node[maxn];
struct Edge {
int x1, y1, z1;
int x2, y2, z2;
};
Edge edge[maxn];
int Z[maxn];
int a[maxn];
int cnt[maxn << ];
int sum1[maxn << ];
int sum2[maxn << ];
int sum3[maxn << ]; void init() {
m = ;
memset(cnt, , sizeof cnt);
memset(sum1, , sizeof sum1);
memset(sum2, , sizeof sum2);
memset(sum3, , sizeof sum3);
memset(node, , sizeof node);
} void pushup(int left, int right, int root) {
if(cnt[root] >= ) {
sum3[root] = sum2[root] = sum1[root] = a[right+] - a[left];
} else if(cnt[root] == ) {
sum2[root] = sum1[root] = a[right+] - a[left];
sum3[root] = sum1[root << ] + sum1[root << | ];
} else if(cnt[root] == ) {
sum1[root] = a[right+] - a[left];
sum3[root] = sum2[root << ] + sum2[root << | ];
sum2[root] = sum1[root << ] + sum1[root << | ];
} else {
sum3[root] = sum3[root << ] + sum3[root << | ];
sum2[root] = sum2[root << ] + sum2[root << | ];
sum1[root] = sum1[root << ] + sum1[root << | ];
}
} void update(int left, int right, int prel, int prer, int val, int root) {
if(prel <= left && right <= prer) {
cnt[root] += val;
pushup(left, right, root);
return ;
}
int mid = (left + right) >> ;
if(prel <= mid) update(left, mid, prel, prer, val, root << );
if(prer > mid) update(mid+, right, prel, prer, val, root << | );
pushup(left, right, root);
} int main() {
int T;
scanf("%d", &T);
int cas = ;
while(T--) {
memset(edge, , sizeof edge);
memset(Z, , sizeof Z);
scanf("%d", &n);
for(int i=; i<=n; i++) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
edge[i].x1 = x;
edge[i].y1 = y;
edge[i].z1 = z;
Z[*i-] = z;
scanf("%d%d%d", &x, &y, &z);
edge[i].x2 = x;
edge[i].y2 = y;
edge[i].z2 = z;
Z[*i] = z;
}
sort(Z+, Z++*n);
int zz = unique(Z+, Z++*n) - (Z+);
ll ans = ;
for(int i=; i<zz; i++) {
init();
for(int j=; j<=n; j++) {
if(edge[j].z1 <= Z[i] && Z[i+] <= edge[j].z2) {
node[m].l = edge[j].x1;
node[m].r = edge[j].x2;
node[m].h = edge[j].y1;
node[m].f = ;
a[m++] = edge[j].x1;
node[m].l = edge[j].x1;
node[m].r = edge[j].x2;
node[m].h = edge[j].y2;
node[m].f = -;
a[m++] = edge[j].x2;
}
}
m--;
sort(node+, node++m);
sort(a+, a++m);
int nn = unique(a+, a++m) - (a+);
for(int j=; j<m; j++) {
int l = lower_bound(a+, a++nn, node[j].l) - a;
int r = lower_bound(a+, a++nn, node[j].r) - a;
update(, m, l, r-, node[j].f, );
ans += 1ll * sum3[] * (node[j+].h - node[j].h) * (Z[i+] - Z[i]);
}
}
printf("Case %d: %lld\n", cas++, ans);
}
return ;
}

Get The Treasury HDU - 3642(体积扫描线)的更多相关文章

  1. Get The Treasury HDU - 3642(扫描线求三维面积交。。体积交)

    题意: ...就是求体积交... 解析: 把每一层z抽出来,计算面积交, 然后加起来即可..! 去看一下 二维面积交的代码 再看看这个三维面积交的代码.. down函数里 你发现了什么规律!!! 参考 ...

  2. Q - Get The Treasury - HDU 3642 (扫面线求体积)

    题意:求被三个或三个以上立方体重合的体积 分析:就是平面面积的加强,不过归根还是一样的,可以把z轴按照从小向大分区间N个,然后可以得到N个平面,用平面重复三次以上的在和高度计算体积. ******** ...

  3. hdu 3642 体积并

    题意:求三个矩形体积的并 链接:点我 枚举z #include<stdio.h> #include<iostream> #include<stdlib.h> #in ...

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

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

  5. HDU 3511 圆扫描线

    找最深的圆,输出层数 类似POJ 2932的做法 圆扫描线即可.这里要记录各个圆的层数,所以多加一个维护编号的就行了. /** @Date : 2017-10-18 18:16:52 * @FileN ...

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

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

  7. HDU 3642 扫描线(立方体体积并)

    Get The Treasury Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

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

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

  9. hdu 3642 Get The Treasury (三维的扫描线)

    题目大意: 给出N个立方体. 求一个三维空间中被包围三次的空间的体积之和. 思路分析: 发现Z的范围非常小.那么我们能够枚举Z轴,然后对 x y做扫描线. 并且不用枚举全部的Z ,仅仅须要将Z离散化之 ...

随机推荐

  1. 上古神器之Vim编辑器

    在Linux操作环境下进行文本的编辑少不了编辑器vi ,vim,nona... 一. 修改颜色方案 有时候,使用vim打开一个文件,竟然是蓝色的,辨识度相当的差,这个时候,我们可以调整 一下颜色的搭配 ...

  2. react插件包

    react-scoped-style support ie8,ie8+,chrome,firefox,safari does not support css priority (just apply ...

  3. react单组件 渲染页面

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Docker入门了解一下(第一篇)

    最近在学docker.k8s什么的,看得脑子有点乱.从来没弄过在linux上搭建一个分布式的环境,所以对这些不太了解,还是从最简单的地方剖析吧. Docker学习传送:http://www.ityou ...

  5. 利用 Docker 搭建单机的 Cloudera CDH 以及使用实践

    想用 CDH 大礼包,于是先在 Mac 上和 Centos7.4 上分别搞个了单机的测试用.其实操作的流和使用到的命令差不多就一并说了: 首先前往官方下载包: https://www.cloudera ...

  6. Java 基础类型 默认值

    (1)数据库里的列,如果有默认值,不能赋值有业务含义的值. (2)int 默认值 java会分配默认值的额.

  7. Java第一次实训

    package com.wsy.work; public class JudgeNumber { public static void main(String[] args) { int a = 5; ...

  8. vue环境搭建+vscode

    https://blog.csdn.net/junshangshui/article/details/80376489

  9. 九、.net core用orm继承DbContext(数据库上下文)方式操作数据库

    一.创建一个DataContext普通类继承DbContext  安装程序集:Pomelo.EntityFrameworkCore.MySql   二.配置连接字符串(MySql/SqlServer都 ...

  10. MySQL创建远程用户并授权

    今天需要在本地测试系统功能,因为本地没有数据库,就需要在程序里面连接远程数据库: 先用ssh登录远程服务器,用root连上数据库看看情况: mysql> select Host,User,Pas ...