1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
| // // main.cpp // HDU2771 // // Created by zhangmin chen on 2019/3/4. // Copyright © 2019 zhangmin chen. All rights reserved. //
using namespace std;
const int maxw = 1000 + 1; const int maxn = 50 + 10;
const int dx[] = {1, -1, 0, 0, 0, 0}; const int dy[] = {0, 0, 1, -1, 0, 0}; const int dz[] = {0, 0, 0, 0, 1, -1};
int read() { int x; scanf("%d", &x); return x; }
// get sculpture int x0[maxn], y0[maxn], z0[maxn], x1[maxn], y1[maxn], z1[maxn]; int xs[maxn*2], ys[maxn*2], zs[maxn*2]; int nx, ny, nz; // nx++, ny++, nz++
int color[maxn*2][maxn*2][maxn*2];
// discretize: // x[0] is the smallest, x[1] is the largest // x_from = getID(x, nx, x[0]) x_to = getID(x, nx, x[1])
// vol: (xs[i+1]-xs[i]) * (ys[i+1]-ys[i]) * (zs[i+1]-zs[i]) void discretize(int* x, int& n) { sort(x, x+n); n = unique(x, x+n) - x; }
int getID(int* x, int n, int v) { return lower_bound(x, x+n, v) - x; }
void init() { xs[0] = ys[0] = zs[0] = 0; xs[1] = ys[1] = zs[1] = maxw; nx = ny = nz = 2; }
struct POS { int x, y, z; POS(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} bool inRange() const { return x >= 0 && x < nx-1 && y >= 0 && y < ny-1 && z >= 0 && z < nz-1; } POS neighbor(int dir) { return POS(x+dx[dir], y+dy[dir], z+dz[dir]); } // POS np = pos.neighbor(), if(!np.inRange()) continue bool solid() const { return color[x][y][z] == 1; } void setVis() { color[x][y][z] = 2; }
bool isVisted() const { return color[x][y][z] == 2; } // if (!np.isVisited()) que.push(np) int volume() const { return (xs[x+1]-xs[x]) * (ys[y+1]-ys[y]) * (zs[z+1]-zs[z]); } int area(int dir) const { if(dx[dir] != 0) return (ys[y+1] - ys[y]) * (zs[z+1] - zs[z]); else if(dy[dir] != 0) return (xs[x+1] - xs[x]) * (zs[z+1] - zs[z]); return (xs[x+1] - xs[x]) * (ys[y+1] - ys[y]); } };
void bfs(int& vm, int& cm) { vm = cm = 0; POS start; queue<POS> que; start.setVis(); que.push(start); while(!que.empty()) { POS fr = que.front(); que.pop(); vm += fr.volume(); for(int i = 0; i < 6; i++) { POS np = fr.neighbor(i); if(!np.inRange()) continue; if(np.solid()) cm += np.area(i); else if(!np.isVisted()) { np.setVis(); que.push(np); } } } //debug(maxw*maxw*maxw); //debug(vm); vm = maxw * maxw * maxw - vm; }
int m; int main() { freopen("input.txt", "r", stdin); int kase; kase = read(); while(kase--) { init(); m = read(); for(int i = 0; i < m; i++) { scanf("%d%d%d%d%d%d", &x0[i], &y0[i], &z0[i], &x1[i], &y1[i], &z1[i]); // I made a bug here //debug(x0[i]); debug(y0[i]); debug(z0[i]); x1[i] += x0[i]; y1[i] += y0[i]; z1[i] += z0[i]; xs[nx++] = x0[i]; xs[nx++] = x1[i]; ys[ny++] = y0[i]; ys[ny++] = y1[i]; zs[nz++] = z0[i]; zs[nz++] = z1[i]; } discretize(xs, nx); discretize(ys, ny); discretize(zs, nz); //debug(nx), debug(ny), debug(nz); // build sculpture" Set(color, 0); for(int i = 0; i < m; i++) { int xbeg = getID(xs, nx, x0[i]), xend = getID(xs, nx, x1[i]); //debug(xbeg), debug(xend); int ybeg = getID(ys, ny, y0[i]), yend = getID(ys, ny, y1[i]); int zbeg = getID(zs, nz, z0[i]), zend = getID(zs, nz, z1[i]); FOR(px, xbeg, xend) FOR(py, ybeg, yend) FOR(pz, zbeg, zend) color[px][py][pz] = 1; } // bfs(): int cm, vm; bfs(vm, cm); printf("%d %d\n", cm, vm); } }
|