#include#include const int N = 2505; int n, q, h1, m1, h2, m2, time1, time2, vis[20][20][20][105], tim; struct Point { int x, y, z; Point() {} void scan() { scanf("%d%d%d", &x, &y, &z); } } p, s, e, v; bool judge(int x, int y, int z, int ti) { int i, j, k, l; for (i = x; i < x + v.x; i++) { for (j = y; j < y + v.y; j++) { for (k = z; k < z + v.z; k++) { for (l = ti; l < ti + tim; l++) { if (vis[i][j][k][l]) return false; } } } } return true; } int solve() { int ans = 0, i, j, k, t; for (i = 0; i <= p.x - v.x; i++) { for (j = 0; j <= p.y - v.y; j++) { for (k = 0; k <= p.z - v.z; k++) { for (t = 0; t <= 96 - tim; t++) { if (judge(i, j, k, t)) { ans++; } } } } } return ans; } int main() { int cas = 0; while (~scanf("%d%d%d%d%d", &n, &p.x, &p.y, &p.z, &q) && n) { memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; i++) { s.scan(); e.scan(); scanf("%d:%d%d:%d", &h1, &m1, &h2, &m2); time1 = h1 * 4 + m1 / 15; time2 = h2 * 4 + m2 / 15; for (int x = s.x; x < e.x; x++) { for (int y = s.y; y < e.y; y++) { for (int z = s.z; z < e.z; z++) { for (int t = time1; t < time2; t++) { vis[x][y][z][t] = 1; } } } } } printf("3D World %d:\n", ++cas); while (q--) { v.scan(); scanf("%d:%d", &h1, &m1); tim = h1 * 4 + m1 / 15; int ans = solve(); if (ans) printf("%d safe place(s) found\n", ans); else printf("No safe place(s) found\n"); } } return 0; }
#include#include const int N = 20; const int M = 105; int sum[N][N][N][M], n, dx, dy, dz, q, b0, b1, b2, b3; void tra(int bit) { b0 = bit&1; b1 = (bit>>1)&1; b2 = (bit>>2)&1; b3 = (bit>>3); } int coeff() { return (b0 + b1 + b2 + b3) % 2 == 1 ? 1 : -1; } int solve(int x, int y, int z, int t) { int ans = 0; for (int i = 1; i <= dx - x + 1; i++) for (int j = 1; j <= dy - y + 1; j++) for (int k = 1; k <= dz - z + 1; k++) for (int l = 1; l <= 96 - t + 1; l++) { int s = 0; for (int bit = 0; bit < 16; bit++) { tra(bit); s += sum[i - 1 + b0 * x][j - 1 + b1 * y][k - 1 + b2 * z][l - 1 + b3 * t] * coeff(); } if (!s) ans++; } return ans; } int main() { int cas = 0; while (~scanf("%d%d%d%d%d", &n, &dx, &dy, &dz, &q) && n) { memset(sum, 0, sizeof(sum)); printf("3D World %d:\n", ++cas); while (n--) { int x1, y1, z1, x2, y2, z2, h1, m1, h2, m2; scanf("%d%d%d%d%d%d%d:%d%d:%d", &x1, &y1, &z1, &x2, &y2, &z2, &h1, &m1, &h2, &m2); int t1 = h1 * 4 + m1 / 15, t2 = h2 * 4 + m2 / 15; for (int i = x1 + 1; i <= x2; i++) for (int j = y1 + 1; j <= y2; j++) for (int k = z1 + 1; k <= z2; k++) for (int l = t1 + 1; l <= t2; l++) sum[i][j][k][l] = 1; } for (int i = 1; i <= dx; i++) for (int j = 1; j <= dy; j++) for (int k = 1; k <= dz; k++) for (int l = 1; l <= 96; l++) for (int bit = 1; bit < 16; bit++) { tra(bit); sum[i][j][k][l] += sum[i - b0][j - b1][k - b2][l - b3] * coeff(); } while (q--) { int x, y, z, h, m; scanf("%d%d%d%d:%d", &x, &y, &z, &h, &m); int t = h * 4 + m / 15; int ans = solve(x, y, z, t); if (ans) printf("%d safe place(s) found\n", ans); else printf("No safe place(s) found\n"); } } return 0; }