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(扫描线)的更多相关文章

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

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

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

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

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

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

  4. HDU 3642 Get The Treasury (线段树扫描线)

    题意:给你一些长方体,问你覆盖三次及以上的体积有多大 首先我们观察x轴y轴一样很大,但是z轴很小,所以我们可以枚举z轴(-500,500),注意我们枚举的是每一段长度为一的z轴的xy轴的面积而不是点. ...

  5. HDU 3642 Get The Treasury 线段树+分层扫描线

    http://www.acmerblog.com/hdu-3642-get-the-treasury-6603.html 学习:三维就是把竖坐标离散化分层,每一层进行线段树二维面积并就好了

  6. hdu 3642 Get The Treasury

    Get The Treasury http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Othe ...

  7. HDU - 3642 Get The Treasury(线段树求体积交)

    https://cn.vjudge.net/problem/HDU-3642 题意 求立方体相交至少3次的体积. 分析 三维的呢..首先解决至少覆盖三次的问题.则用三个标记,更新时的细节要注意. 注意 ...

  8. HDU 3642 Get The Treasury ( 线段树 求长方体体积并 )

    求覆盖三次及其以上的长方体体积并. 这题跟 http://wenku.baidu.com/view/d6f309eb81c758f5f61f6722.html 这里讲的长方体体积并并不一样. 因为本题 ...

  9. Get The Treasury HDU - 3642(体积扫描线)

    给出n个立方体,要你求这些立方体至少被覆盖三次的部分. 先把这个立方体的信息存在来,发现Z的范围不大,z范围是是[-500,500],所以我们可以先离散化,然后枚举Z, 然后对于每一段Z的区域内,在当 ...

随机推荐

  1. 【BZOJ3673】【可持久化并查集】可持久化并查集 by zky

    Description n个集合 m个操作操作:1 a b 合并a,b所在集合2 k 回到第k次操作之后的状态(查询算作操作)3 a b 询问a,b是否属于同一集合,是则输出1否则输出0 0<n ...

  2. 总结Widows 7 Start->Run 命令

    Widows + R基本上成为很常用的方式,那么通过Windows + R我们可以在运行中做什么手脚呢. 下面从最基本的系统命令说起 notepad--------打开记事本    services. ...

  3. 利用sfntly的sfnttool.jar提取中文字体

    雨忆博客中提到了sfntly(具体介绍可以看:https://code.google.com/p/sfntly/),利用其中sfnttool.jar就可以提取只包含指定字符的字体,如果想在页面中通过@ ...

  4. mysql数据类型——浮点和定点型

    mysql数据类型 字节 含义 float(m,d)           4字节  单精度浮点型,8位精度,m是十进制数字的总个数,d是小数点后面的数字个数 double(m,d)        8字 ...

  5. PHP面向对象(OOP):把对象串行化serialize()方法,__sleep()方法,__wakeup()方法

    有时候需要把一个对象在网络上传输,为了方便传输,可以把整个对象转化为二进制串,等到达另一端时,再还原为原来的对象,这个过程称之为串行化(也叫序列化), 就像我们现在想把一辆汽车通过轮船运到美国去,因为 ...

  6. EasyUI篇のico

    所有图标位置: /themes/icons css引用位置: /themes/icon.css 可自行添加16*16的小图片放在icons中,icon.css代码添加即可 例如: .icon-logo ...

  7. JS获取select选中的值

    var oSel=oFl.getElementsByTagName('select')[0]; oSel.onchange=function(){ var indexselect=oSel.selec ...

  8. 关于C#匿名方法

    作者  陈嘉栋(慕容小匹夫) 阅读目录 0x00 前言 0x01 不必构造委托对象 0x02 匿名方法初探 0x03 使用匿名方法省略参数 0x04 匿名方法和闭包 0x05 匿名方法如何捕获外部变量 ...

  9. Java中swap解惑

    直接上代码…… public class Swap { public static void main(String[] args) { int a[] = new int[]{1,2}; Syste ...

  10. UNITY3D 破碎 shatter

    convex mesh collider + shatter rigidbody  ,