UVA12171_Sculpture_坐标旋转45度映射&&离散化
2018-01-14 16:47
387 查看
题意
某雕塑有 n 个边长平行于坐标轴的长方体组成。用每个长方体左上角的坐标,以及长方体的长宽高表示每个长方体。要求统计这个长方体的体积和表面积。其中,体积包含封闭在内部的空间,但表面积不包含在外面看不到的面。思路
假想是从一个大的立方体中抠出这个雕塑,通过BFS计算多余体积,再从立方体中抠掉即可。同时,表面积也可以计算出来。题目坐标系比较大,需要离散化。一开始有一点没想明白,怎么处理相邻两个长方体是否连接起来。实际上,只需要在描述长方体的长宽高区间时,采用左开右闭的方法处理即可。
链接
https://vjudge.net/problem/UVA-12171代码
#include<iostream> #include<cstdio> #include<queue> #include<vector> #include<algorithm> #include<cstring> using namespace std; const int maxx = 1010; const int maxn = 100+10; struct node{ int x, y, z; node(){} node(int x,int y, int z):x(x), y(y), z(z){} void read(){scanf("%d %d %d", &x, &y, &z);} node operator +(node a){ return node(x + a.x, y + a.y, z + a.z); } void show(){ printf("%d %d %d\n", x, y, z); } }; node mov[6]; int T, n; node P[maxn]; vector<int> X, Y, Z; bool G[maxn][maxn][maxn]; bool vis[maxn][maxn][maxn]; void push_in(node &a){ X.push_back(a.x); Y.push_back(a.y); Z.push_back(a.z); } void compress(vector<int> &a){ a.push_back(0); a.push_back(maxx); sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); } int get_id(int< 4000 /span> d, vector<int> &D){ return lower_bound(D.begin(), D.end(), d) - D.begin(); } int get_area(node &d, int dir){ if(mov[dir].z != 0) return (X[d.x+1] - X[d.x]) * (Y[d.y+1] - Y[d.y]); else if(mov[dir].y != 0) return (X[d.x+1] - X[d.x]) * (Z[d.z+1] - Z[d.z]); return (Y[d.y+1] - Y[d.y]) * (Z[d.z+1] - Z[d.z]); } int main(){ mov[0] = node(1, 0, 0); mov[1] = node(-1, 0, 0); mov[2] = node(0, 1, 0); mov[3] = node(0, -1, 0); mov[4] = node(0, 0, 1); mov[5] = node(0, 0, -1); scanf("%d", &T); while(T--){ int v = 0, s = 0; X.clear();Y.clear();Z.clear(); memset(vis, false, sizeof vis); memset(G, false, sizeof G); scanf("%d", &n); for(int i = 0; i < (n<<1); i+=2){ P[i].read(); P[i+1].read(); P[i+1] = P[i] + P[i+1]; push_in(P[i]); push_in(P[i+1]); } compress(X); compress(Y); compress(Z); //构造离散化的小图 for(int i = 0; i < (n<<1); i += 2){ int x0 = get_id(P[i].x, X), x1 = get_id(P[i+1].x, X); int y0 = get_id(P[i].y, Y), y1 = get_id(P[i+1].y, Y); int z0 = get_id(P[i].z, Z), z1 = get_id(P[i+1].z, Z); for(int x = x0; x < x1; ++x){ for(int y = y0; y < y1; ++y){ for(int z = z0; z < z1; ++z){ G[x][y][z] = true; } } } } queue<node> qu; qu.push(node(0, 0, 0)); vis[0][0][0] = true; while(!qu.empty()){ node t = qu.front(); qu.pop(); if(!G[t.x][t.y][t.z]){ v += (X[t.x+1] - X[t.x]) * (Y[t.y+1] - Y[t.y]) * (Z[t.z+1] - Z[t.z]); } for(int i = 0; i < 6; ++i){ node mt = t + mov[i]; if(mt.x < 0 || mt.x >= X.size()-1 || mt.y < 0 || mt.y >= Y.size()-1 || mt.z < 0 || mt.z >= Z.size()-1) continue; if(G[mt.x][mt.y][mt.z]){ s += get_area(mt, i); }else if(!vis[mt.x][mt.y][mt.z]){ qu.push(mt); vis[mt.x][mt.y][mt.z] = true; } } } printf("%d %d\n", s, maxx * maxx * maxx - v); } return 0; }
相关文章推荐
- UVa12171 Sculpture 离散化+搜索
- UVa 12171 (离散化 floodfill) Sculpture
- uva12171 sculpture 离散化 3维bfs求面积体积
- UVA 12171 Sculpture 离散化 floodfil 立方体体积并 转换
- UVa 11178 Morley's Theorem (向量旋转)
- HDU4456-Crowd(坐标旋转+二位树状数组+离散化)
- 将picture控件坐标 映射为逻辑坐标1000×1000
- HDU 4087 三维坐标旋转(仿射变换) 矩阵加速 && 2011 Asia Beijing Regional Contest
- UVA - 12171 Sculpture
- UVA 11178 || Morley's Theorem (向量旋转求交点
- UVA 152-Tree's a Crowd(暴力求解三维坐标求最短距离)
- uva 11178 - Morley's Theorem (直线旋转相交)
- uva 12171 hdu 1771 Sculpture
- 如何判断任意四个点可以组成矩形及正方形 && 点绕另外一个点旋转后的坐标
- UVa 12171 Sculpture
- UVA 12171 (hdu 2771)sculptrue(离散化)
- HDU 4325&& nyoj 600 Flowers【线段树+坐标离散化】
- 已知2个坐标点,求从 0------->x 逆时针需旋转多少角度到该位置
- 坐标轴旋转+二维树状数组离散化
- UVa12171 Sculpture