HDU 3642 Get The Treasury(线段树)
来源:互联网 发布:sql insert 多条 编辑:程序博客网 时间:2024/05/17 06:12
HDU 3642 Get The Treasury
题目链接
题意:给定一些立方体,求体积重叠超过3次的
思路:由于z坐标只有500,那么就可以枚举z坐标,每次做x,y的面积并即可,用线段树维护
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 1005;const int INF = 0x3f3f3f3f;typedef long long ll;int t, n;struct Cube {int x1, y1, z1, x2, y2, z2;void read() {scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2);}} cube[N];struct Line {int l, r, y, flag;Line() {}Line(int l, int r, int y, int flag) {this->l = l; this->r = r;this->y = y; this->flag = flag;}} line[N * 2];bool cmp(Line a, Line b) {return a.y < b.y;}int hash[N * 2], ln, hn;int find(int x) {return lower_bound(hash, hash + hn, x) - hash;}#define lson(x) ((x<<1)+1)#define rson(x) ((x<<1)+2)struct Node {int l, r, cover, len[4];void init(int l, int r) {this->l = l; this->r = r;cover = 0;memset(len, 0, sizeof(len));}} node[N * 8];void build(int l, int r, int x = 0) {node[x].init(l, r);node[x].len[0] = hash[r + 1] - hash[l];if (l == r) return;int mid = (l + r) / 2;build(l, mid, lson(x));build(mid + 1, r, rson(x));}void pushup(int x) {memset(node[x].len, 0, sizeof(node[x].len));if (node[x].l == node[x].r) {node[x].len[min(3, node[x].cover)] = hash[node[x].r + 1] - hash[node[x].l];return;}for (int i = 0; i <= 3; i++)node[x].len[min(3, node[x].cover + i)] += node[lson(x)].len[i] + node[rson(x)].len[i];}void add(int l, int r, int v, int x = 0) {if (node[x].l >= l && node[x].r <= r) {node[x].cover += v;pushup(x);return;}int mid = (node[x].l + node[x].r) / 2;if (l <= mid) add(l, r, v, lson(x));if (r > mid) add(l, r, v, rson(x));pushup(x);}ll solve(int z) {ln = hn = 0;for (int i = 0; i < n; i++) {if (cube[i].z1 <= z && cube[i].z2 > z) {line[ln++] = Line(cube[i].x1, cube[i].x2, cube[i].y1, 1);line[ln++] = Line(cube[i].x1, cube[i].x2, cube[i].y2, -1);hash[hn++] = cube[i].x1; hash[hn++] = cube[i].x2;}}sort(line, line + ln, cmp);sort(hash, hash + hn);int tmp = 1;for (int i = 0; i < hn; i++)if (hash[i] != hash[i - 1])hash[tmp++] = hash[i];hn = tmp;ll ans = 0;build(0, hn - 2);for (int i = 0; i < ln; i++) {if (i) ans += (ll)node[0].len[3] * (line[i].y - line[i - 1].y);add(find(line[i].l), find(line[i].r) - 1, line[i].flag);}return ans;}int main() {int cas = 0;scanf("%d", &t);while (t--) {scanf("%d", &n);int Minz = INF, Maxz = -INF;for (int i = 0; i < n; i++) {cube[i].read();Minz = min(Minz, cube[i].z1);Maxz = max(Maxz, cube[i].z2);}ll ans = 0;for (int i = Minz; i < Maxz; i++)ans += solve(i);printf("Case %d: %lld\n", ++cas, ans);}return 0;}
1 0
- 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
- 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(离散化+线段树:扫描线)
- HDU 3642 Get The Treasury[离散化 + 扫描线 + 线段树]
- HDU 3642 Get The Treasury (线段树 体积交[转成面积交])
- HDU 3642 Get The Treasury(体积并+覆盖三次+线段树+扫描线)
- HDU_3642 Get The Treasury 线段树
- 线段树 hdu3642 Get The Treasury
- HDU 3642 Get The Treasury(体积并,离散化)
- android tabActivity中 onKeyDown无效解决 退出功能
- 【springMVC 学习三】springmvc常用注解之@Controller和@RequestMapping
- email linux 发送邮件
- PHP利用header跳转失效解决方法
- 关于mysql不能显示中文的问题,简单解决方案~
- HDU 3642 Get The Treasury(线段树)
- ——Diary5(Java面向对象2——多态,内部类)
- Android笔记 使用Json从数据库读取数据+demo
- 每天一个JavaScript实例-apply和call的用法
- Linux忘记root密码
- StringUtils的API
- 类 Properties 的用法
- 仿射变换生成玫瑰花结
- dom4j解析一个xml报文,如果是java项目解析没有任何问题,可是放在weblogic下面解析就出现错