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的区域内,在当 ...
随机推荐
- 中级Perl 第三章课后习题
3. 10. 1. 练习1 [25 分钟] 读当前目录的文件列表并转换成全路径.不能用shell 命令或外部程序读当前目 录.Perl 的File::Spec 和Cwd 两个模块对这个程序有帮助.每个 ...
- 《用chsh选择shell》-linux命令五分钟系列之十二
chsh命令用于修改你的登录shell. 1 我想知道我机器安装了哪些shell? 两种方法可以查看: 第一种: [rocrocket@wupengchong ~]$ chsh -l /bin/sh ...
- php实现返回上一页的功能的3种有效方法
php实现返回上一页的功能的3种有效方法 header(location:你的上一页的路径); // 注意这个函数前不能有输出 header(location:.getenv("HT ...
- 如何将eclipse里的项目发布到github
首先,给eclipse安装上EGit 在“Help > Install new software”中添加 http://download.eclipse.org/egit/updates 两个都 ...
- Start Your Django Project in Nginx with uWsgi
Step 0:Install A,B,C,blabla needed This can be seen in my another article in the blog.click here(una ...
- [Usaco2006 Dec]Milk Patterns
[Usaco2006 Dec]Milk Patterns Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天 产奶的质量,但连续的若干天的 ...
- 粗谈CGI
先看看 维基百科上面关于 CGI的介绍http://zh.wikipedia.org/wiki/%E9%80%9A%E7%94%A8%E7%BD%91%E5%85%B3%E6%8E%A5%E5%8F% ...
- VLAN间通信----实验
方法1.增加物理线路 需求:PC0连接SW的F0/1,PC1连接SW的F0/2; SW创建VLAN10,VLAN20; PC0划到VLAN10; PC1划到VLAN20; 现要求借用路 ...
- MySql可视化工具MySQL Workbench使用教程
1. MySQL Workbench MySQL Workbench 为数据库管理员.程序开发者和系统规划师提供可视化的Sql开发.数据库建模.以及数据库管理功能. 2.MySQL Workbench ...
- js 实现 aop
Aop又叫面向切面编程,用过spring的同学肯定对它非常熟悉,而在js中,AOP是一个被严重忽视的技术点,这篇就通过下面这几个小例子,来说说AOP在js中的妙用. 1, 防止window.onloa ...