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

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

题目大意:先给出4个数,M行,N列,L共有几块,T阈值。1表示中风,0表正常,如果两块有相同的边,那么它们就是相连的。肿瘤块大小大于T才是肿瘤。

//这个真看不太懂,以前看过的,都不理解,什么意思,什么是块连在一起了呢?真不理解啊。

代码转自:https://www.liuchuo.net/archives/2307

#include <cstdio>
#include <queue>
using namespace std;
struct node {
int x, y, z;
};
int m, n, l, t;
int X[] = {, , , -, , };//方向依次是:同一个平面上:下,右,往下一个平面正下,
int Y[] = {, , , , -, };//同一个平面,上,左,往上一个平面上
int Z[] = {, , , , , -};
int arr[][][];
bool visit[][][];
bool judge(int x, int y, int z) {
if(x < || x >= m || y < || y >= n || z < || z >= l) return false;
if(arr[x][y][z] == || visit[x][y][z] == true) return false;
return true;
}
int bfs(int x, int y, int z) {
int cnt = ;
node temp;
temp.x = x, temp.y = y, temp.z = z;
queue<node> q;
q.push(temp);
visit[x][y][z] = true;
while(!q.empty()) {
node top = q.front();
q.pop();
cnt++;//这里对块进行计数。
for(int i = ; i < ; i++) {
int tx = top.x + X[i];//6个方向进行判断。
int ty = top.y + Y[i];
int tz = top.z + Z[i];
if(judge(tx, ty, tz)) {
//这里需要判断下标是否是合法的,并且数组是否是1或者未被访问过。
visit[tx][ty][tz] = true;
temp.x = tx, temp.y = ty, temp.z = tz;
q.push(temp);
}
}
}
if(cnt >= t)
return cnt;
else
return ;//否则返回0. }
int main() {
scanf("%d %d %d %d", &m, &n, &l, &t);
for(int i = ; i < l; i++)
for(int j = ; j < m; j++)
for(int k = ; k < n; k++)//使用三维数组存储。
scanf("%d", &arr[j][k][i]);//先读入进来。
int ans = ;
for(int i = ; i < l; i++) {
for(int j = ; j < m; j++) {
for(int k = ; k < n; k++) {//对每一个点都开始遍历,
if(arr[j][k][i] == && visit[j][k][i] == false)
ans += bfs(j, k, i);//i=0时,也就是从第0块开始。
}
}
}
printf("%d", ans);
return ;
}

//代码是看懂了,但是有点疑问,就是如果l不是5呢?为什么它们就有公共的边呢?这里也没有进行判断啊,还不不明白。

1.使用三维数据进行输入,并且标记是否被访问过,使用bfs进行遍历。

2.对六个方向都进行了判断,并且使用了一个judge函数判断下标是否越界,并且是否可以访问该点,十分厉害,值得学习。

3.使用bfs也就是需要用到队列,判断条件是队列是否为空,学习了。

PAT 1091 Acute Stroke [难][bfs]的更多相关文章

  1. PAT 1091. Acute Stroke (bfs)

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

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

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

  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. 1091 Acute Stroke (30)(30 分)

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

  6. 1091 Acute Stroke

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

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

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

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

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

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

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

随机推荐

  1. sql one

    查询的话 子查询什么的都很正常 添加的话 尽量把东西都添加在一个表单里 这是源头 有个这个方便的源头 查询和删除都会方便很多 组建一个网站,不可避免的要进行调试,有些功能需要添加或者删除,对于后台来讲 ...

  2. Differential Geometry之第七章曲面的若干整体性质

    1.曲面的整体描述 2.整体的Gauss-Bonnet公式 2.1.曲面的三角剖分 2.2.Gauss-Bonnet公式 = 2.3.Gauss-Bonnet定理的应用 2.3.1.切向量场的指数定理 ...

  3. 【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1682 最小生成树裸题.. #include <cstdio> #include < ...

  4. 选择LoadRunner Protocol的两大定律

    选择LoadRunner Protocol的两大定律 确定性能测试脚本录制时使用的协议类型经常是一个容易引起误会的问题.很多刚刚接触到性能测试的同行常常会想当然地根据开发语言等来决定协议的选取,导致录 ...

  5. VC++ 窗口拆分CSplitterWnd

    前言         当前许多优秀的软件都采用“多视”技术. 所谓“多视”,是指在同一个框架窗口里同时显示多个视图. 通过运用这种技术,可以在框架的有限控件内同时提供用户更大的信息量,并且使得用户界面 ...

  6. Oracle的归档日志

    归档模式的特点和要求 在归档模式下,当LGWR后台进程的写操作从一个重做日志组切换到另一个重做日志组后,归档写后台进程(ARCH/ARCRn)就会将原来的重做日志的信息复制到归档日志文件中. 可以把归 ...

  7. VS2010类模板更改,增加版权等等信息

    本文转载自XDOTNET 在开发过程中往往需要在每一个页面(类)增加注释等等内容,VS2010中可以修改模板,在原有模板中增加一个类,会引用System等等命名空间,以及一些程序集.下面我们来看看如何 ...

  8. 【BZOJ1495】[NOI2006]网络收费 暴力+DP

    [BZOJ1495][NOI2006]网络收费 Description 网络已经成为当今世界不可或缺的一部分.每天都有数以亿计的人使用网络进行学习.科研.娱乐等活动.然而,不可忽视的一点就是网络本身有 ...

  9. mysql 修改默认配置 提高性能

    解决问题 Lost connection to MySQL server at ‘reading authorization packet’, system error: 0 通过修改 connect ...

  10. js如何遍历并取出对象的属性名?

    js如何遍历并取出对象的属性名? dataObj = {name : su,age : 26,height : 18cm }; for(var st in dataObj) {console.dir( ...