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. SHELL脚本自动备份Linux系统

    今天来写一个使用shell脚本增量备份系统文件,顺便复习一下shell脚本相关的命令,这个脚本可以根据自己的需求来备份不同的文件或者文件夹,进行完整备份和增量备份.直接上脚本如下: #!/bin/sh ...

  2. innerHtml写法

    swt_center = "<div id='new_swt_wee'>"; swt_center += '<a href="javascript:vo ...

  3. 那些年被我坑过的Python——玄而又玄(第六章 面向对象编程基础)

    面向对象编程: 面向对象顾名思义,就是把组织代码的粒度从函数级别抽象到对象级别,对象是通过类来生成的,类可以想象为模板或进本框架而对象是在原有模板或框架的基础上增加详细信息的实体,类,有分类.聚类的含 ...

  4. C#后台找不到前台html标签

    没关系!   只要他在form表单里  , 咱在标签加上一个   runat="server"就可以在后台cs代码里找到他了

  5. hadoop 生态系统版本对应问题

    http://hbase.apache.org/book.html 这是hortonworks的哦哦哦哦哦哦哦哦哦哦哦哦 Hadoop 2.x is better than Hadoop 1.x Ha ...

  6. core dump

    Core Dump?! 整理:Wilbur Lang 何谓 core? 在使用半导体作为内存的材料前,人类是利用线圈当作内存的材料(发明 者为王安),线圈就叫作 core ,用线圈做的内存就叫作 co ...

  7. BZOJ 3570 动物园

    Description 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决定开设算法班,让动物们学习 ...

  8. NXP LPC11xx I2C Slave 从机程序

    /**************************************************************************** * $Id:: i2cslave.c 363 ...

  9. setjmp/longjmp 使用

    C语言中有一个goto语句,其可以结合标号实现函数内部的任意跳转(通常情况下,很多人都建议不要使用goto语句,因为采用goto语句后,代码维护工作量加大).另外,C语言标准中还提供一种非局部跳转“n ...

  10. Java socket 说明 以及web 出现java.net.SocketException:(Connection reset或者Connectreset by peer:Socket write error)的解释

    另外http://www.cnblogs.com/fengmk2/archive/2007/01/15/using-Socket.html可供参考   一Java socket 说明 所谓socket ...