PAT 1091 Acute Stroke

                                                                                PAT 1091 Acute Stroke

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 Specification:

Each input file contains one test case. For each case, the first line contains 4 positive integers: M, N, L and T, where M and N are the sizes of each slice (i.e. pixels of a slice are in an M×N matrix, and the maximum resolution is 1286 by 128); L (60) is the number of slices of a brain; and T is the integer threshold (i.e. if the volume(容量) of a connected core is less than T, then that core must not be counted).

Then L slices are given. Each slice is represented by an M×N matrix of 0's and 1's, where 1 represents a pixel of stroke, and 0 means normal. Since the thickness of a slice is a constant, we only have to count the number of 1's to obtain the volume. However, there might be several separated core regions in a brain, and only those with their volumes no less than T are counted. Two pixels are connected and hence belong to the same region if they share a common side, as shown by Figure 1 where all the 6 red pixels are connected to the blue one.

Figure 1

Output Specification:

For each case, output in a line the total volume of the stroke core.

Sample Input:

 

Sample Output:

26

 

解题思路:

1、看完题目,感觉人都快奔溃了,题目这啥意思啊,理解不清楚题意,因此看了算法笔记的翻译,大概理解到该题就是在书上例题的基础上,扩充为了3维,求“1”的块。

2、依据例题的思路,自己独立将该题代码写出来了,但以为求的是块的个数,所以算出的结果不是最终答案,题目要求得是所有卒中核心区中1的个数总和,而不是求卒中核心区的个数

 

注意点:

1、理解不同维数的增量数组的写法,刚开始写这种BFS题目时,对这个的由来很困惑,对PAT的这个增量数组开始也非常疑惑,但其实它理解起来是很简单的,二维时该数组每个index分别表示的是,上、下、左、右。三维时该数组每个index分别表示的是,前、后、上、下、左、右。例如在X[]中的左右上写上1、-1就表示在X轴的左右进行偏移。

二维是:

int X[]={0,0,1,-1}(左右);

int Y[]={1,-1,0,0}(上下);

三维是

int X[] = {0, 0, 0, 0, 1, -1};//左右

int Y[] = {0, 0, 1, -1, 0, 0}; //上下

int Z[] = {1, -1, 0, 0, 0, 0}; //前后

 

 

 

代码:

#include<iostream>

#include<queue>

using namespace std;

const int maxN = 1290, maxM = 130, maxL = 61;

int Marx[maxL][maxN][maxM];//3维矩阵,用来存储0,1矩阵

bool inq[maxL][maxN][maxM]={false};//是否入队

int X[] = {0, 0, 0, 0, 1, -1};//左右

int Y[] = {0, 0, 1, -1, 0, 0}; //上下

int Z[] = {1, -1, 0, 0, 0, 0}; //前后

int m, n, l, t;

int count = 0;//统计1的个数

struct Node

{

    int x, y, z;

}node;

bool judge(int x,int y, int z){

        if(x<0||x>=m||y<0||y>=n||z<0||z>=l)

            return false;//越界

        if(inq[z][x][y]||Marx[z][x][y]==0)

            return false;//已入队或该点为0

        return true;

}

void BFS(int z,int x,int y){

    queue<Node> qN;

    node.x = x;

    node.y = y;

    node.z = z;

    qN.push(node);

    inq[z][x][y] = true;//设置队首元素已入队

    while (!qN.empty())

    {

        Node top = qN.front();//取队首结点

        qN.pop();//弹出队首结点

        for (int i = 0; i < 6; i++)//访问队首元素

        {

            int newX = top.x + X[i];

            int newY = top.y + Y[i];

            int newZ = top.z + Z[i];

            if (judge(newX,newY,newZ))

            {

                count++;//1的数目增加

                node.x = newX;

                node.y = newY;

                node.z = newZ;

                qN.push(node);//入队

                inq[newZ][newX][newY] = true;//该点已入队

            }

            

        }

        

    }

    

}

int main(){

    scanf("%d%d%d%d", &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++)

            {

                scanf("%d", &Marx[i][j][k]);//z,x,y的顺序

            }

        }

    }

    //求解

    int ans = 0;

    for (int i = 0; i < l; i++)

    {

        for (int j = 0; j < m; j++)

        {

            for (int k = 0; k < n; k++)

            {

                if (inq[i][j][k] == false && Marx[i][j][k]==1)

                {

                    count = 1;

                    BFS(i, j, k);

                    if(count>=t){//不少于t个则为一个块

                        ans+=count;

                    }

                }

            }

        }

    }

    cout << ans<<endl;

    system("pause");

    return 0;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Acute3D Viewer是一款用于查看Acute3D软件生成的三维模型的软件。以下是Acute3D Viewer的安装教程。 第一步,打开Acute3D Viewer的安装文件,双击运行该文件。 第二步,选择您要将Acute3D Viewer安装到的目标文件夹。您可以选择默认目标文件夹,也可以自定义目标文件夹。点击“下一步”继续。 第三步,选择开始菜单文件夹。您可以选择将Acute3D Viewer的快捷方式添加到开始菜单的默认文件夹,也可以选择创建一个新的文件夹。点击“下一步”继续。 第四步,选择额外任务。您可以选择添加Acute3D Viewer的桌面快捷方式和快速启动图标。点击“下一步”继续。 第五步,选择安装类型。您可以选择完全安装或者自定义安装。如果您对安装过程不了解,建议选择默认安装。点击“下一步”继续。 第六步,点击“安装”按钮开始安装Acute3D Viewer。安装过程可能需要一些时间,请耐心等待。 第七步,等待安装完成。安装完成后,您可以选择打开Acute3D Viewer。 第八步,启动Acute3D Viewer。在启动Acute3D Viewer之前,系统可能会提示您选择连接Acute3D Viewer的3D模型文件的默认应用程序。您可以选择Acute3D Viewer作为默认应用程序,然后单击“确定”。 这样,您就成功地安装了Acute3D Viewer。现在,您可以使用Acute3D Viewer来查看和浏览Acute3D软件生成的三维模型了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值