HDU 3642 Get The Treasury (线段树 体积交[转成面积交])
来源:互联网 发布:吉利剃须刀哪款好 知乎 编辑:程序博客网 时间:2024/06/07 06:21
题意:
求n 个长方体的体积交(至少三次以上)。
思路:
因为Z的范围比较小。
直接暴力Z轴, 把所有Z轴转成 二维的平面。
直接求z个 面积交即可。
注意 区间是 一闭一开。
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn = 2000 + 10;int T, ks;struct node{ int l,r; int len[4]; int addr;}nod[maxn<<2];struct RECT{ int x,y,x1,y1; RECT(int x = 0,int y = 0,int x1 = 0, int y1 = 0):x(x), y(y), x1(x1), y1(y1){}};vector<RECT>v[maxn>>1];struct LINE{ int l,r; int h; int cnt; LINE(int l = 0,int r = 0,int h = 0,int cnt = 0):l(l), r(r), h(h), cnt(cnt){}}line[maxn];bool cmp(const LINE& lhs, const LINE& rhs){ return lhs.h < rhs.h || (lhs.h == rhs.h && lhs.cnt > rhs.cnt);}int a[maxn];int cnt, id2;int get(int x){ int l = 0,r = id2 - 1, m; while(l <= r){ m = l + r >> 1; if (a[m] == x) return m; else if (a[m] > x){ r = m - 1; } else l = m + 1; }}void pushup(int o){ int l = nod[o].l; int r = nod[o].r; if (l == r){ if (nod[o].addr >= 3){ nod[o].len[3] = nod[o].len[0]; nod[o].len[2] = nod[o].len[1] = 0; } else if (nod[o].addr >= 2){ nod[o].len[3] = nod[o].len[1] = 0; nod[o].len[2] = nod[o].len[0]; } else if (nod[o].addr >= 1){ nod[o].len[2] = nod[o].len[3] = 0; nod[o].len[1] = nod[o].len[0]; } else { nod[o].len[1] = nod[o].len[2] = nod[o].len[3] = 0; } return; } int lson = o << 1; int rson = o << 1 | 1; if (nod[o].addr >= 3){ nod[o].len[3] = nod[o].len[0]; nod[o].len[1] = nod[o].len[2] = 0; } else if (nod[o].addr >= 2){ nod[o].len[3] = 0; for (int i = 1; i <= 3; ++i){ nod[o].len[3] += nod[lson].len[i]; nod[o].len[3] += nod[rson].len[i]; } nod[o].len[1] = 0; nod[o].len[2] = nod[o].len[0] - nod[o].len[3]; } else if (nod[o].addr >= 1){ nod[o].len[3] = 0; for (int i = 2; i <= 3; ++i){ nod[o].len[3] += nod[lson].len[i]; nod[o].len[3] += nod[rson].len[i]; } nod[o].len[2] = nod[lson].len[1] + nod[rson].len[1]; nod[o].len[1] = nod[o].len[0] - nod[o].len[3] - nod[o].len[2]; } else { nod[o].len[3] = nod[lson].len[3] + nod[rson].len[3]; nod[o].len[2] = nod[lson].len[2] + nod[rson].len[2]; nod[o].len[1] = nod[lson].len[1] + nod[rson].len[1]; }}void build(int l,int r,int o){ nod[o].l = l; nod[o].r = r; nod[o].addr = 0; nod[o].len[0] = a[r] - a[l-1]; for (int i = 1; i <= 3; ++i){ nod[o].len[i] = 0; } if (l == r) { return; } int m = l + r >> 1; int lson = o << 1; int rson = o << 1 | 1; build(l,m,lson); build(m+1,r,rson); nod[o].len[0] = nod[lson].len[0] + nod[rson].len[0];}void update(int L,int R,int c,int l,int r,int o){ if (L <= l && r <= R){ nod[o].addr += c; pushup(o); return; } int m = l + r >> 1; if (m >= L){ update(L,R,c,l,m,o<<1); } if (m < R){ update(L,R,c,m+1,r,o<<1|1); } pushup(o);}long long solve(int id){ if ((int)v[id].size() < 3) return 0; cnt = id2 = 0; for (int i = 0; i < v[id].size(); ++i){ int x = v[id][i].x; int y = v[id][i].y; int x1 = v[id][i].x1; int y1 = v[id][i].y1; line[cnt++] = LINE(x,x1, y, 1); line[cnt++] = LINE(x,x1, y1, -1); a[id2++] = x; a[id2++] = x1; } sort(a,a+id2); id2 = unique(a, a + id2) - a; sort(line, line + cnt, cmp); build(1, id2-1, 1); update(get(line[0].l) + 1, get(line[0].r), line[0].cnt, 1, id2 - 1, 1); long long ans = 0; for (int i = 1; i < cnt; ++i){ ans += (long long)nod[1].len[3] * (line[i].h - line[i-1].h); update(get(line[i].l) + 1, get(line[i].r), line[i].cnt, 1, id2 - 1, 1); } return ans;}int main(){ scanf("%d",&T); while(T--){ for (int i = 0; i < (maxn >> 1); ++i ){ v[i].clear(); } int n; scanf("%d",&n); for (int i = 0; i < n; ++i){ int x,y,z,x1,y1,z1; scanf("%d %d %d %d %d %d", &x, &y, &z, &x1, &y1, &z1); for (int j = z; j < z1; ++j){ v[j + 500].push_back(RECT(x,y,x1,y1)); } } long long ans = 0; for (int i = 0; i <= 1000; ++i){ ans += solve(i); } printf("Case %d: %I64d\n", ++ks, ans); } return 0;}
Get The Treasury
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2720 Accepted Submission(s): 881
Problem Description
Jack knows that there is a great underground treasury in a secret region. And he has a special device that can be used to detect treasury under the surface of the earth. One day he got outside with the device to ascertain the treasury. He chose many different locations on the surface of the earth near the secret region. And at each spot he used the device to detect treasury and got some data from it representing a region, which may contain treasury below the surface. The data from the device at each spot is six integers x1, y1, z1, x2, y2 and z2 (x1<x2, y1<y2, z1<z2). According to the instruction of the device they represent the range of x, y and z coordinates of the region. That is to say, the x coordinate of the region, which may contain treasury, ranges from x1 to x2. So do y and z coordinates. The origin of the coordinates is a fixed point under the ground.
Jack can’t get the total volume of the treasury because these regions don’t always contain treasury. Through years of experience, he discovers that if a region is detected that may have treasury at more than two different spots, the region really exist treasure. And now Jack only wants to know the minimum volume of the treasury.
Now Jack entrusts the problem to you.
Jack can’t get the total volume of the treasury because these regions don’t always contain treasury. Through years of experience, he discovers that if a region is detected that may have treasury at more than two different spots, the region really exist treasure. And now Jack only wants to know the minimum volume of the treasury.
Now Jack entrusts the problem to you.
Input
The first line of the input file contains a single integer t, the number of test cases, followed by the input data for each test case.
Each test case is given in some lines. In the first line there is an integer n (1 ≤ n ≤ 1000), the number of spots on the surface of the earth that he had detected. Then n lines follow, every line contains six integers x1, y1, z1, x2, y2 and z2, separated by a space. The absolute value of x and y coordinates of the vertices is no more than 106, and that of z coordinate is no more than 500.
Each test case is given in some lines. In the first line there is an integer n (1 ≤ n ≤ 1000), the number of spots on the surface of the earth that he had detected. Then n lines follow, every line contains six integers x1, y1, z1, x2, y2 and z2, separated by a space. The absolute value of x and y coordinates of the vertices is no more than 106, and that of z coordinate is no more than 500.
Output
For each test case, you should output “Case a: b” in a single line. a is the case number, and b is the minimum volume of treasury. The case number is counted from one.
Sample Input
210 0 0 5 6 430 0 0 5 5 53 3 3 9 10 113 3 3 13 20 45
Sample Output
Case 1: 0Case 2: 8
Source
2010 Asia Regional Hangzhou Site —— Online Contest
Recommend
lcy
阅读全文
0 0
- HDU 3642 Get The Treasury (线段树 体积交[转成面积交])
- HDU 3642 Get The Treasury (线段树、扫描线求立方体体积交)
- Hdu 3642 Get The Treasury(长方体的体积交)
- HDU 3642——Get The Treasury(线段树+扫描线+离散化+体积交多次)
- hdoj 3642 Get The Treasury 【线段树 扫描线 求立方体积交】
- 【hdu3642】Get The Treasury (立方体体积交+线段树+扫描线)
- hdu 3642 Get The Treasury 扫描线求长方体体积交
- hdu 3642 Get The Treasury(线段树求体积并)
- hdu-3642--Get The Treasury-线段树求面积并
- hdu 3642 Get The Treasury(扫描线、立方体交)
- HDU 3642 Get The Treasury(体积并+覆盖三次+线段树+扫描线)
- HDU 3642 Get The Treasury (线段树扫描线进阶--求长方体重叠3次或以上的体积)
- 【线段树 && 扫描线 && 面积交】HDU
- HDU 3642 Get The Treasury(线段树)
- HDU 3642 Get The Treasury 【线段树】【扫描线】
- HDU 3642 Get The Treasury(体积并,离散化)
- HDU 3642 Get The Treasury(线段树+扫描线求面积【再升级版(三维)】)
- hdu 1542 ,1255 线段树面积并与面积交
- 机器学习之正则化(Regularization)
- Scala练习-基数排序
- zsh和bash的区别
- oracle 连接到空闲例程的处理
- 1. Two Sum/[3]167. Two Sum II
- HDU 3642 Get The Treasury (线段树 体积交[转成面积交])
- 51Nod 1058 N的阶乘的长度
- Touch Mode, Selection, and Focus
- 配置java环境变量
- Java算法【冒泡排序】
- Android WebView 上传图片(以5.0为分界点)不同的处理方式
- 方法的调用
- shell if用法
- Context启动Activity哪些坑