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
#include <cstdio>
#include <queue>
using namespace std;struct node {int x, y, z;
}Node;int n, m, slice, T;
int pixel[1290][130][61];
bool inq[1290][130][61] = {false};int X[6] = { 0,0,0,0,1,-1 };
int Y[6] = { 0,0,1,-1,0,0 };
int Z[6] = { 1,-1,0,0,0,0 };bool judge(int x, int y, int z) {if (x >= n || x < 0 || y >= m || y < 0 || z >= slice || z < 0)return false;if (pixel[x][y][z] == 0 || inq[x][y][z] == true)return false;return true;}int BFS(int x, int y, int z) {int tot = 0;//计数当前块中1的个数queue<node> Q;Node.x = x; Node.y =y; Node.z = z;Q.push(Node);inq[x][y][z] = true;while (!Q.empty()) {node top = Q.front();Q.pop();tot++;//块中1的个数增加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)) {Node.x = newX;Node.y = newY;Node.z = newZ;Q.push(Node);inq[newX][newY][newZ] = true;}}}if (tot >= T)return tot;else return 0;}int main() {scanf("%d%d%d%d", &n, &m, &slice, &T);for (int z = 0; z < slice; z++) {for (int x = 0; x < n; x++) {for (int y = 0; y < m; y++) {scanf("%d", &pixel[x][y][z]);}}}int ans = 0;for (int z = 0; z < slice; z++) {for (int x = 0; x < n; x++) {for (int y = 0; y < m; y++) {if (pixel[x][y][z] == 1 && inq[x][y][z]==false) {ans += BFS(x, y, z);}}}}printf("%d\n", ans);return 0;
}

1091 Acute Stroke (30 分)广度优先搜索,用queue,重写一遍相关推荐

  1. 【PTA-A】1091 Acute Stroke (30 分)(BFS、队列)

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

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

    三维搜索,按照6个邻接理论,总会有重合的部分区域, 因此根据搜索顺序,先访问到的就是一个区域的[不能较真] #include <bits/stdc++.h> using namespace ...

  3. 1091 Acute Stroke (30 分)【难度: 一般 / bfs】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072 很常见的题,就是求每一个连通块的大小. #i ...

  4. 【PAT甲级题解】1091 Acute Stroke (30分) BFS

    本题考BFS应用,题目大意是给出一个三维0,1矩阵,你需要对任意一个元素的上下左右前后进行判断枚举,如果当前元素为1且满足要求,则入队,当前枚举结束后如果该'1'矩阵不小于一个'l'代表的阈值则返回其 ...

  5. 1091. Acute Stroke (30)-PAT甲级真题(广度优先搜索)

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

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

  8. PAT甲级 1091 Acute Stroke(30) (Flood Fill)

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

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

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

  10. pat1091. Acute Stroke (30)

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

最新文章

  1. CV01-语义分割笔记和两个模型VGG ResNet的笔记
  2. html:漂亮的原生表格_HTML表格:关于它们的所有知识
  3. 独立硬盘冗余阵列与HDFS
  4. Bitmap 多语言实现及应用
  5. 数据要素市场的组织形式和估值框架
  6. C# 程序Hello World
  7. PDF复制文本快速去除换行,解决段落错乱
  8. linux dbm数据库,linux dbm数据库
  9. 阿里云开发者大会观后感
  10. Docker——Dockerfile 介绍和使用
  11. 360P2建html网站,360 P2路由器密码怎么设置?
  12. js抓取字符串中的电话号码
  13. java from space to space_快速定位Java 内存OOM的问题
  14. 《娱乐至死》读书笔记
  15. latex从入门到精通
  16. linux4.1内核配置以及编译及千兆网卡dp83867网卡驱动移植
  17. weautomate rpa开发心得
  18. Video标签播放视频(动态视频URL)
  19. ios程序员的创业之路
  20. 开源协议是什么?有哪些?如何选择?

热门文章

  1. Drawable解析1——ColorDrawable、BitmapDrawable、ClipDrawabl和ScaleDrawable
  2. Unity:一键移除所有预制体上的Missing脚本
  3. http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd 报红
  4. 重构Webpack系列之二 ---- 入口起点
  5. 从键盘录入10个整数,统计有多少个奇数,Java基础轻松实现
  6. abb外部轴零位校准_【ABB】ABB机器人外部轴参数(KpKvTi)调试
  7. python爬取网页代码_python爬虫爬取网页的内容和网页源码不同?
  8. 仓库镜像源为清华_conda国内镜像修改(最新版)
  9. Java—读取指定路径下文件的内容
  10. C# WPF中DataGrid的数据绑定(Binding)