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离散化之 ...
随机推荐
- [转帖]SAP一句话入门:Finacial & Controlling Accounting
SAP一句话入门:Finacial & Controlling Accounting http://blog.vsharing.com/MilesForce/A621147.html 财务,财 ...
- 2.请介绍一下List和ArrayList的区别,ArrayList和HashSet区别
第一问: List是接口,ArrayList实现了List接口. 第二问: ArrayList实现了List接口,HashSet实现了Set接口,List和Set都是继承Collection接口. A ...
- html 引入页面公共部分(header、footer)
html引入页面的公共部分,比如导航栏啊,页头页脚之类的. 1.将需要引入的公共html部分转换为js文件,这里推荐一个转换工具地址 http://tool.chinaz.com/Tools/Html ...
- 解决小程序webview缓存机制
在打开webview的时候在地址后面加上随机数或者字符串 并且H5页面使用文件hash
- 部署wp 的时候遭遇的google字体问题
国内WP CDN问题昨天下午到今天中午 总算解决了WORDPRESS 在 谷歌字体被枪毙之后带来的一系列问题..在天朝想当个 安静的美男子设计师也是那么烦恼的事情捏! 解决办法将所有的带fonts.g ...
- Java多线程之synchronized线程锁
package org.study2.javabase.ThreadsDemo.sync; /** * @Auther:GongXingRui * @Date:2018/9/18 * @Descrip ...
- MySQL的FIND_IN_SET()函数
今天在做项目时,看到了一个从没见过的MySQL函数——FIND_IN_SET(),顿时就产生了浓郁的兴趣,然后就搜了搜,翻了翻. 语法:FIND_IN_SET(str,strlist) 定义: 1. ...
- Ubuntu install flash
Software&Updates - Other Software - Canonical Parners sudo apt install adobe-flashplugin
- CentOS 安装git
git安装 yum install git 初始化git “git init --bare 文件夹” 添加所有 “git add . ” 提交 “git commit -m "提交信息&qu ...
- mpvue——引入antv-F2图表
踩坑中~ 官方文档 https://www.yuque.com/antv/f2/intro 毕竟不像echarts接触过,所以还是先看看文档较好 github https://github.com/s ...