搜索专题 BFS A1091.Acute Stroke(30)

#pragma warning(disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <queue>
using namespace std;
struct node{
    int x, y, z;
}p;
int m, n, l, t, volume = 0;
int brain[1300][130][61], bbrain[1300][130][61];
//右,左,上,下,前,后
int X[] = { 0, 0, 0, 0, 1, -1 };
int Y[] = { 1, -1, 0, 0, 0, 0 };
int Z[] = { 0, 0, 1, -1, 0, 0 };
bool judge(int x, int y, int z){
    if (x >= m || x < 0 || y >= n || y < 0 || z >= l || z < 0)    return false;
    if (!brain[x][y][z] || bbrain[x][y][z])    return false;
    return true;
}
int BFS(int x, int y, int z){
    int cnt = 0;
    queue<node> qn;
    p.x = x;
    p.y = y;
    p.z = z;
    qn.push(p);
    bbrain[x][y][z] = 1;
    while (!qn.empty()){
        node top = qn.front();
        qn.pop();
        cnt++;
        for (int i = 0; i < 6; i++){
            int nx = top.x + X[i], ny = top.y + Y[i], nz = top.z + Z[i];
            if (judge(nx, ny, nz)){
                p.x = nx;
                p.y = ny;
                p.z = nz;
                qn.push(p);
                bbrain[nx][ny][nz] = 1;
            }
        }
    }
    if (cnt >= t)    return cnt;
    else return 0;
}
int main(){
    scanf("%d %d %d %d", &m, &n, &l, &t);
    for (int k = 0; k < l; k++)
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
                scanf("%d", &brain[i][j][k]);
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < l; k++)
                if (brain[i][j][k] && bbrain[i][j][k] == 0)
                    volume += BFS(i, j, k);
    printf("%d\n", volume);
    system("pause");
    return 0;

}

参考:https://blog.csdn.net/ztmajor/article/details/81393476

原文地址:https://www.cnblogs.com/JasonPeng1/p/12215884.html

时间: 2024-10-02 20:35:31

搜索专题 BFS A1091.Acute Stroke(30)的相关文章

A1091. 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

A1091 Acute Stroke (30分)

一.技术总结 这一题是BFS广度优先搜索算法,感觉这类题目是首先定义需要的数据结构类型,然后会定义一个数组用于存放数据,还有一个bool类型的数组看是否已经放入队列中了.然后再编写一个判断函数judge()排除数组中超出范围的数字返回false,还有就是不满足条件或者是已经在队列中的,最后就返回true. 同时也应该定义一个广度扩散的二维或三维数组. 编写BFS函数,首先定义需要的变量,然后定义一个队列终于记录,把传入的参数赋给数据结构,然后push进入队列中,然后再编写while循环,只要队列

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 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. 输入描述:

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

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是存储在队列中,每次队列都会有状态取