1091 acute stroke

三维空间的DFS,挺新颖的一题

AC代码:

#include <vector>
#include <cstdio>
#include <queue>
using namespace std;
int x[] = {0,0,1,0,-1,0};
int y[] = {0,1,0,-1,0,0};
int z[] = {-1,0,0,0,0,1};
class node{
public:
    int x;
    int y;
    int z;
    node(int xx,int yy,int zz):x(xx),y(yy),z(zz){}
    node(){}
};
int main(){
    int n,m,l,t;
    scanf("%d %d %d %d",&n,&m,&l,&t);
    vector<vector<vector<int>>> cub;
    vector<vector<vector<bool>>> vs;
    for(int i = 0;i < l;i++){
        vector<vector<int>> p;
        vector<vector<bool>> pvs;
        for(int j = 0;j < n;j++){
            vector<int> line;
            vector<bool> vline;
            for(int k = 0;k < m;k++){
                int tmp;
                scanf("%d",&tmp);
                line.push_back(tmp);
                vline.push_back(false);
            }
            p.push_back(line);
            pvs.push_back(vline);
        }
        cub.push_back(p);
        vs.push_back(pvs);
    }
    int num(0);
    for(int i = 0;i < l;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < m;k++){
                if(vs[i][j][k] || cub[i][j][k] == 0)
                    continue;
                else{
                    queue<node> q;
                    node tmp(j,k,i);
                    q.push(tmp);
                    vs[i][j][k] = true;
                    int count(1);
                    while(!q.empty()){
                        for(int s = 0;s < 6;s++){
                            node son(q.front().x + x[s],q.front().y + y[s],q.front().z + z[s]);
                            if(son.z >= 0 && son.z < l && son.x >= 0 && son.x < n && son.y >= 0 && son.y < m && !vs[son.z][son.x][son.y]
                                && cub[son.z][son.x][son.y] == 1){
                                vs[son.z][son.x][son.y] = true;
                                q.push(son);
                                count++;
                            }
                        }
                        q.pop();
                    }
                    if(count >= t)
                        num += count;
                }
            }
        }
    }
    printf("%d\n",num);
    return 0;
}
时间: 2024-10-11 13:14:58

1091 acute stroke的相关文章

1091. Acute Stroke (30)【搜索】——PAT (Advanced Level) Practise

题目信息 1091. Acute Stroke (30) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice,

PAT 1091. Acute Stroke (30)

1091. Acute Stroke (30) One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the

PAT 1091 Acute Stroke [难][bfs]

1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of th

PAT甲级——1091 Acute Stroke (广度优先搜索BFS)

本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/94207638 1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions

【PAT甲级】1091 Acute Stroke (30分)

1091 Acute Stroke (30分) One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the

1091. Acute Stroke (30)

One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core. Input Spec

PAT甲题题解-1091. Acute Stroke (30)-BFS

题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写,想有没有别的办法.然而结果是,实在想不出别的办法了,所以还是尝试写写dfs.bfs. 一开始先用了dfs,最后两个样例段错误,估计是栈溢出了.之所以dfs栈溢出,因为dfs的时候每个状态都会存储在堆栈里,就好比dfs的第一个状态,一直保存到最后整个dfs结束.而bfs是存储在队列中,每次队列都会有状态取

PAT (Advanced Level) 1091. Acute Stroke (30)

BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<stack> #include<vector> using namespace std; int M,N,L,T; int A[70][1300][133]; bo

pat1091. Acute Stroke (30)

1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are iden