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
| #include<iostream> #include<queue> using namespace std; struct node { int x, y, z; node(int newz, int newy, int newx) :z(newz), y(newy), x(newx) {} }; int G[60][1286][128]; int M, N, L, T;
queue<node*>q; int dix[6] = { 0,0,-1,1,0,0 }; int diy[6] = { -1,1,0,0,0,0 }; int diz[6] = { 0,0,0,0,-1,1 }; int rx = 0, ry = 0, rz = 0; int cnt = 0; int temp = 0; void BFS() { while (!q.empty()) { temp++; node* top = q.front(); q.pop(); for (int i = 0; i < 6; i++) { int newx = dix[i] + top->x; int newy = diy[i] + top->y; int newz = diz[i] + top->z; if (newx >= 0 && newx < N) { if (newy >= 0 && newy < M) { if (newz >= 0 && newz < L) { if (G[newz][newy][newx]) { G[newz][newy][newx] = 0; q.push(new node(newz, newy, newx)); }
} } } } } } int main() { cin >> M >> N >> L >> T; for (int i = 0; i < L; i++) { for (int j = 0; j < M; j++) { for (int k = 0; k < N; k++) { cin >> G[i][j][k]; } } } for (int i=0; i < L; i++) { for (int j=0; j < M; j++) { for (int k=0; k < N; k++) { if (G[i][j][k] == 1) { G[i][j][k] = 0; node* r = new node(i, j, k); q.push(r); BFS(); if (temp >= T) { cnt += temp; } temp = 0; } }
}
} cout << cnt; }
|