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 (≤) 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:

3 4 5 2
1 1 1 1
1 1 1 1
1 1 1 1
0 0 1 1
0 0 1 1
0 0 1 1
1 0 1 1
0 1 0 0
0 0 0 0
1 0 1 1
0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1
1 0 0 0

Sample Output:

26

 #include <iostream>
#include <queue>
using namespace std;
struct Node
{
int x, y, z;
Node(int xx, int yy, int zz) :x(xx), y(yy), z(zz) {}
};
int M, N, L, T, res = ;
int direct[][] = { {-,,},{,,},{,-,},{,,},{,,-},{,,} };
bool G[][][];//遍历记录
int BFS(Node p)
{
int num = ;
queue<Node>q;
q.push(p);
G[p.x][p.y][p.z] = false;
while (!q.empty())
{
p = q.front();
q.pop();
++num;
for (int i = ; i < ; ++i)
{
int x = p.x + direct[i][];
int y = p.y + direct[i][];
int z = p.z + direct[i][];
if (x < M && x >= && y >= && y < N && z >= && z <= L && G[x][y][z])
{
q.push(Node(x, y, z));
G[x][y][z] = false;
}
}
}
return num;
}
int main()
{
cin >> M >> N >> L >> T;
for (int k = ; k < L; ++k)
for (int i = ; i < M; ++i)
for (int j = ; j < N; ++j)
cin >> G[i][j][k];
for(int i=;i<M;++i)
for(int j=;j<N;++j)
for(int k=;k<L;++k)
if (G[i][j][k])
{
int temp = BFS(Node(i, j, k));
if (temp >= T)
res += temp;
}
cout << res << endl;
return ;
}

PAT甲级——A1091 Acute Stroke【30】的更多相关文章

  1. PAT甲级1091 Acute Stroke【三维bfs】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072 题意: 求三维的连通块 思路: 简单b ...

  2. pat1091. Acute Stroke (30)

    1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...

  3. 【PAT】1091 Acute Stroke(30 分)

    1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

  4. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  5. A1091. Acute Stroke

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  6. 1091 Acute Stroke (30)(30 分)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

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

    题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...

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

    BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...

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

    题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...

随机推荐

  1. 【POJ】1182 食物链

    这是<挑战设计程序竞赛>中的例题. 题目链接:http://poj.org/problem?id=1182 题意:中文题面.不赘述. 题解: 代码: //带权并查集 #include< ...

  2. unity3D笔记の四种调用其他脚本方法

    第一种,被调用脚本函数为static类型,调用时直接用  脚本名.函数名() 第二种,GameObject.Find("脚本所在的物体的名字").SendMessage(" ...

  3. FaceNet pre-trained模型以及FaceNet源码使用方法和讲解

    Pre-trained models Model name LFW accuracy Training dataset Architecture 20180408-102900 0.9905 CASI ...

  4. canvas基础用法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. TCP三次握手形象理解

    tcp三次握手就像是你用企业微信给人家发信息,首先你得确认别人在不在,你会发  在吗?  这个时候显示的是未读   对方看到之后未读会变成已读 然后他会回复你  在的    你看到这个消息后,他那边也 ...

  6. 【JZOJ6275】小L的数列

    description analysis 考虑矩阵乘法 设初始\(m×m\)矩阵上\(i\)行\(j\)列的数字表示该矩阵第\(j\)位上\(f[i]\)的指数 那么一开始表示\(f[1..k]\)的 ...

  7. git使用过程中问题

    git提交文件命令顺序 fetch merge add commit pull push 取消已add文件 git reset HEAD 文件名 覆盖本地文件 git checkout 文件名 $ g ...

  8. Bubble Cup 12 - Finals [Online Mirror, unrated, Div. 1] E. Product Tuples

    题意略,题解生成函数练习题,1+(q-ai)x卷积即可,线段树优化(类似分治思想) //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pra ...

  9. WordPress 3.8 中文正式版下载 - 建站与学习首选!全球最流行的开源PHP博客网站程序

    转载自:http://www.iplaysoft.com/wordpress.html 话说虽然我一直都在网站底部写着本站基于 WordPress 构建,但时常还是有人问我网站是用什么程序建的,还真有 ...

  10. 使用gulp搭建less编译环境

    什么是less? 一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承, 运算, 函数. LESS 既可以在 客户端 上运行 (支持IE 6+, Webkit, Fi ...