Get The Treasury HDU - 3642(体积扫描线)
给出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(体积扫描线)的更多相关文章
- Get The Treasury HDU - 3642(扫描线求三维面积交。。体积交)
题意: ...就是求体积交... 解析: 把每一层z抽出来,计算面积交, 然后加起来即可..! 去看一下 二维面积交的代码 再看看这个三维面积交的代码.. down函数里 你发现了什么规律!!! 参考 ...
- Q - Get The Treasury - HDU 3642 (扫面线求体积)
题意:求被三个或三个以上立方体重合的体积 分析:就是平面面积的加强,不过归根还是一样的,可以把z轴按照从小向大分区间N个,然后可以得到N个平面,用平面重复三次以上的在和高度计算体积. ******** ...
- hdu 3642 体积并
题意:求三个矩形体积的并 链接:点我 枚举z #include<stdio.h> #include<iostream> #include<stdlib.h> #in ...
- hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...
- HDU 3511 圆扫描线
找最深的圆,输出层数 类似POJ 2932的做法 圆扫描线即可.这里要记录各个圆的层数,所以多加一个维护编号的就行了. /** @Date : 2017-10-18 18:16:52 * @FileN ...
- HDU 3642 - Get The Treasury - [加强版扫描线+线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- HDU 3642 扫描线(立方体体积并)
Get The Treasury Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- hdu 3642 Get The Treasury (三维的扫描线)
题目大意: 给出N个立方体. 求一个三维空间中被包围三次的空间的体积之和. 思路分析: 发现Z的范围非常小.那么我们能够枚举Z轴,然后对 x y做扫描线. 并且不用枚举全部的Z ,仅仅须要将Z离散化之 ...
随机推荐
- Problem 2285 迷宫寻宝
http://acm.fzu.edu.cn/problem.php?pid=2285 Problem Description 洪尼玛今天准备去寻宝,在一个n*n (n行, n列)的迷宫中,存在着一个入 ...
- C# Note21: 扩展方法(Extension Method)及其应用
前言 今天在开会时提到的一个概念,入职3个多月多注重在项目中使用C#的编程知识,一直没有很认真地过一遍C#的全部语法,当我们新人被问及是否了解Extension Method时,一时之间竟不能很通俗准 ...
- 关于 html input标签的几个常用操作
1.清除 input 标签默认样式 input { -moz-appearance: none; outline: 0; text-decoration: none; outline: none; b ...
- 微信小程序自定义组件
要做自定义组件,我们先定一个小目标,比如说我们在小程序中实现一下 WEUI 中的弹窗组件,基本效果图如下. Step1 我们初始化一个小程序(本示例基础版本库为 1.7 ),删掉里面的示例代码,并新建 ...
- python爬虫之Splash使用初体验
Splash是什么: Splash是一个Javascript渲染服务.它是一个实现了HTTP API的轻量级浏览器,Splash是用Python实现的,同时使用Twisted和QT.Twisted(Q ...
- python设计模式第二十天【模版方法模式】
1.应用场景 (1)具有相同的操作,但是步骤中具有不同的操作细节 2.代码实现 #!/usr/bin/env python #! _*_ coding:UTF-8 _*_ from abc impor ...
- Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理
name = models.CharField(max_length=50) 执行:python manage.py makemirations出现以下错误: You are trying to ad ...
- 数据库语法group by
因为在做pgsql和mysql数据库时group by 有报错,但是在以前做mysql5.6的时候没有问题,虽然知道时违反了sql的语法问题,但是没有搞清楚什么原因,也找了不少资料,查找原因,在盆友的 ...
- JUC虚假唤醒(六)
为什么条件锁会产生虚假唤醒现象(spurious wakeup)? 在不同的语言,甚至不同的操作系统上,条件锁都会产生虚假唤醒现象.所有语言的条件锁库都推荐用户把wait()放进循环里: whil ...
- 排列组合n选m算法
找10组合算法,非递归 http://blog.csdn.net/sdhongjun/article/details/51475302