hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury
题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次以上。
解题思路:扫描线,将第三维分离出来,就是普通的二维扫描线,然后对于每一个节点要维护覆盖0,1,2。3以上这4种的覆盖面积。
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 4005;
vector<int> pos;
#define lson(x) ((x)<<1)
#define rson(x) (((x)<<1)|1)
int lc[maxn << 2], rc[maxn << 2], v[maxn << 2], s[maxn << 2][5];
inline void pushup(int u) {
memset(s[u], 0, sizeof(s[u]));
if (v[u] >= 3)
s[u][3] = pos[rc[u]+1] - pos[lc[u]];
else {
if (lc[u] == rc[u])
s[u][v[u]] = pos[rc[u]+1] - pos[lc[u]];
else if (v[u] == 2) {
s[u][2] = s[lson(u)][0] + s[rson(u)][0];
for (int i = 1; i <= 3; i++)
s[u][3] += s[lson(u)][i] + s[rson(u)][i];
} else if (v[u] == 1) {
s[u][1] = s[lson(u)][0] + s[rson(u)][0];
s[u][2] = s[lson(u)][1] + s[rson(u)][1];
for (int i = 2; i <= 3; i++)
s[u][3] += s[lson(u)][i] + s[rson(u)][i];
} else {
for (int i = 0; i <= 3; i++)
s[u][i] = s[lson(u)][i] + s[rson(u)][i];
}
}
}
inline void maintain(int u, int d) {
v[u] += d;
pushup(u);
}
void build (int u, int l, int r) {
lc[u] = l;
rc[u] = r;
v[u] = 0;
if (l == r) {
maintain(u, 0);
return ;
}
int mid = (l + r) / 2;
build (lson(u), l, mid);
build (rson(u), mid + 1, r);
pushup(u);
}
void modify (int u, int l, int r, int d) {
if (l <= lc[u] && rc[u] <= r) {
maintain(u, d);
return;
}
int mid = (lc[u] + rc[u]) / 2;
if (l <= mid)
modify(lson(u), l, r, d);
if (r > mid)
modify(rson(u), l, r, d);
pushup(u);
}
struct Seg {
int x, l, r, d;
Seg (int x = 0, int l = 0, int r = 0, int d = 0) {
this->x = x;
this->l = l;
this->r = r;
this->d = d;
}
};
typedef long long ll;
vector<Seg> g[1005];
inline bool cmp (const Seg& a, const Seg& b) {
return a.x < b.x;
}
void init () {
int n, x1, x2, y1, y2, z1, z2;
scanf("%d", &n);
for (int i = 0; i <= 1000; i++)
g[i].clear();
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2);
for (int i = z1; i < z2; i++) {
g[i + 500].push_back(Seg(x1, y1, y2, 1));
g[i + 500].push_back(Seg(x2, y1, y2, -1));
}
}
}
inline int find (int k) {
return lower_bound(pos.begin(), pos.end(), k) - pos.begin();
}
ll solve (int idx) {
if (g[idx].size() == 0)
return 0;
ll ret = 0;
pos.clear();
sort(g[idx].begin(), g[idx].end(), cmp);
for (int i = 0; i < g[idx].size(); i++) {
pos.push_back(g[idx][i].l);
pos.push_back(g[idx][i].r);
}
sort(pos.begin(), pos.end());
build(1, 0, pos.size());
for (int i = 0; i < g[idx].size(); i++) {
modify(1, find(g[idx][i].l), find(g[idx][i].r) - 1, g[idx][i].d);
if (i + 1 != g[idx].size())
ret += 1LL * s[1][3] * (g[idx][i+1].x - g[idx][i].x);
}
return ret;
}
int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
init();
ll ans = 0;
for (int i = 0; i <= 1000; i++)
ans += solve(i);
printf("Case %d: %I64d\n", kcas, ans);
}
return 0;
}
hdu 3642 Get The Treasury(扫描线)的更多相关文章
- 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 (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- hdu 3642 Get The Treasury (三维的扫描线)
题目大意: 给出N个立方体. 求一个三维空间中被包围三次的空间的体积之和. 思路分析: 发现Z的范围非常小.那么我们能够枚举Z轴,然后对 x y做扫描线. 并且不用枚举全部的Z ,仅仅须要将Z离散化之 ...
- HDU 3642 Get The Treasury (线段树扫描线)
题意:给你一些长方体,问你覆盖三次及以上的体积有多大 首先我们观察x轴y轴一样很大,但是z轴很小,所以我们可以枚举z轴(-500,500),注意我们枚举的是每一段长度为一的z轴的xy轴的面积而不是点. ...
- HDU 3642 Get The Treasury 线段树+分层扫描线
http://www.acmerblog.com/hdu-3642-get-the-treasury-6603.html 学习:三维就是把竖坐标离散化分层,每一层进行线段树二维面积并就好了
- hdu 3642 Get The Treasury
Get The Treasury http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Othe ...
- HDU - 3642 Get The Treasury(线段树求体积交)
https://cn.vjudge.net/problem/HDU-3642 题意 求立方体相交至少3次的体积. 分析 三维的呢..首先解决至少覆盖三次的问题.则用三个标记,更新时的细节要注意. 注意 ...
- HDU 3642 Get The Treasury ( 线段树 求长方体体积并 )
求覆盖三次及其以上的长方体体积并. 这题跟 http://wenku.baidu.com/view/d6f309eb81c758f5f61f6722.html 这里讲的长方体体积并并不一样. 因为本题 ...
- Get The Treasury HDU - 3642(体积扫描线)
给出n个立方体,要你求这些立方体至少被覆盖三次的部分. 先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z, 然后对于每一段Z的区域内,在当 ...
随机推荐
- TextView控件
1.手动创建(不建议): TextView tv = new TextView(this); tv.setContent("你好"); setContentView(tv); 2. ...
- web一点小结
1, AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJAX ...
- shell脚本中的标准输出重定向使用涵义
0表示标准输入 1表示标准输出 2表示标准错误输出 > 默认为标准输出重定向,与 1> 相同 2>&1 意思是把 标准错误输出 重定向到 标准输出. &>fil ...
- Http和Socket连接的区别
Http和Socket连接区别 相信不少初学手机联网开发的朋友都想知道Http与Socket连接究竟有什么区别,希望通过自己的浅显理解能对初学者有所帮助. 1.TCP连接 要想明白Socket连接,先 ...
- 开发DZ插件教程
插件制作的基本思路是:(初学者适用)1.形成插件思路2.制作插件界面3.构架程序模块4.搭建存储数据5.填充功能语句6.检查应用错误7.完善插件功能 前言:为方便互联网数万Discuz!爱好者,更加深 ...
- iOS题
对于语句NSString* testObject = [[NSData alloc] init];关于testObject是什么类型对象,以下说法正确的是: 答案:(A) A.编译时,NSString ...
- KVO/KVC总结
KVO/KVC总结 下面是根据网上文章的总结,方便查看. 在网上看别人的文章,了解KVC.KVO,有个kvo-kvc的例子,就是改变数组的内容(插入和删除),同步改变tableview中的 ...
- Webpack 傻瓜式指南(一)
modules with dependencies webpack module bundler static assetss .js .js .png Webpack傻瓜式指南 n ...
- 使用Flexible 实现手淘H5 页面的终端适配学习
Amfe阿里无线前端团队双11技术连载之际,一个实战案例来展示多终端适配. Device metrics 1.0 mdpi 2.0 xhdpi 3.0xxhdpi(iphone 6 plus) 手淘h ...
- Keil MDK与h-jtag联调
keil MDK也是可以借助h-jtag进行单步调试,写出来与大家一起分享一下. keil MDK编译器使用V4.01版本,下载地址:http://www.embedinfo.com/down-lis ...