• L3004 肿瘤诊断


    #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<XYZ> 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
    
  • 相关阅读:
    [css3]搜索框focus时变长
    [css3]文字过多以省略号显示
    HTML5表单新增属性
    [JS]getYear()和getFullYear()方法区别
    红包彩带动画效果
    ios下input focus弹出软键盘造成fixed元素位置移位
    旋转效果
    移动端前端开发
    如何加快页面加载速度
    centos7/rhel7下安装redis4.0集群
  • 原文地址:https://www.cnblogs.com/ZhengLijie/p/16163769.html
Copyright © 2020-2023  润新知