1. 程式人生 > 其它 >L3-004 腫瘤診斷

L3-004 腫瘤診斷

include <bits/stdc++.h>

using namespace std;

const int N = 1010;
bool vis[1300][130][70];
int dx[5] = {-1, 0, 1, 0, 0}, dy[5] = {0, 1, 0, -1, 0};
int dz[3] = {-1, 0, 1};
int m, n, l, t;
bool qiepian[1300][130][70];

struct XYZ {
int x, y, z;
};

bool check(int a, int b, int c) {
if (a < 0 || a >= m || b < 0 || b >= n || c < 0 || c >= l) return false;
if (qiepian[a][b][c] == 0) return false;
if (vis[a][b][c]) return false;
return true;
}

int bfs(int x, int y, int z) {
queue q;
q.push({x, y, z});
int cnt = 1;
while (q.size()) {
auto t = q.front();
q.pop();

    int x = t.x, y = t.y, z = t.z;
    for (int i = 0; i < 3; i++) {
        //int a = x, b = y, c = z;
        if (dz[i] == 0) {
            for (int j = 0; j < 4; j++) {
                int xx = x + dx[j], yy = y + dy[j];
                //int aa = a + dx[j], bb = b + dy[j];
                if (check(xx, yy, z)) {
                    cnt++;
                    vis[xx][yy][z] = true;
                    q.push({xx, yy, z});
                } 
            }
        } else {
            int zz = z + dz[i];
            //int cc = c + dz[i];
            if (check(x, y, zz)) {
                cnt++;
                vis[x][y][zz] = true;
                q.push({x, y, zz});
            }
        }
    }
}

return cnt;

}

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> m >> n >> l >> t;
for (int z = 0; z < l; z++) {
for (int x = 0; x < m; x++) {
for (int y = 0; y < n; y++) {
cin >> qiepian[x][y][z];
}
}
}

int res = 0;
for (int z = 0; z < l; z++) {
    for (int x = 0; x < m; x++) {
        for (int y = 0; y < n; y++) {
            if (!vis[x][y][z] && qiepian[x][y][z] == 1) {
                vis[x][y][z] = true;
                int num = bfs(x, y, z);
                if (num >= t) res += num;
            }
        }
    }
}

cout << res << "\n";

return 0;

}

// 1 1 1 1
// 1 1 1 1
// 1 1 1 1

// -12

// 0 0 1 1
// 0 0 1 1
// 0 0 1 1

// -18

// 1 0 1 1
// 0 1 0 0
// 0 0 0 0

// -20

// 1 0 1 1
// 0 0 0 0
// 0 0 0 0

// -20 + 2 +

// 0 0 0 1
// 0 0 0 1
// 1 0 0 0