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

题目大意:给定一个三维数组,0表示正常1表示有肿瘤,肿瘤块的大小大于等于t才算作是肿瘤,让计算所有满足肿瘤块的大小

分析:三维的广度优先搜索~XYZ三个数组判断方向,对每一个点广度优先累计肿瘤块的大小,如果大于等于t就把结果累加。用visit数组标记当前的点有没有被访问过,被访问过的结点是不会再访问的。。judge判断是否超过了边界,或者是否当前结点为0不是肿瘤~

#include <cstdio>
#include <queue>
using namespace std;
struct node {int x, y, z;
};
int m, n, l, t;
int X[6] = {1, 0, 0, -1, 0, 0};
int Y[6] = {0, 1, 0, 0, -1, 0};
int Z[6] = {0, 0, 1, 0, 0, -1};
int arr[1300][130][80];
bool visit[1300][130][80];
bool judge(int x, int y, int z) {if(x < 0 || x >= m || y < 0 || y >= n || z < 0 || z >= l) return false;if(arr[x][y][z] == 0 || visit[x][y][z] == true) return false;return true;
}
int bfs(int x, int y, int z) {int cnt = 0;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 = 0; i < 6; i++) {int tx = top.x + X[i];int ty = top.y + Y[i];int tz = top.z + Z[i];if(judge(tx, ty, tz)) {visit[tx][ty][tz] = true;temp.x = tx, temp.y = ty, temp.z = tz;q.push(temp);}}}if(cnt >= t)return cnt;elsereturn 0;}
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", &arr[j][k][i]);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(arr[j][k][i] == 1 && visit[j][k][i] == false)ans += bfs(j, k, i);}}}printf("%d", ans);return 0;
}

1091. Acute Stroke (30)-PAT甲级真题(广度优先搜索)相关推荐

  1. 1091 Acute Stroke (PAT甲级)

    这道题用dfs做的话,因为递归太多层,堆栈溢出,有两个测试点过不了:所以用bfs. 根据他人代码修改后的结果: #include <cstdio> #include <vector& ...

  2. 1131. Subway Map (30)-PAT甲级真题 (DFS or 堆优化dij or SPFA)

    题意 给出地铁线路数n,分别给出每条线的站点数m,再依次列出站点id.然后询问k次从启点sv到终点ev的最短路径,如果最短路径相同,要求换乘最少的路径.最后按条件输出. 思路 1.用unordered ...

  3. PAT甲级真题目录(按题型整理)(转自柳神)

    转载自:https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg 最短路径 1003. Emergency (25)-PAT甲级真 ...

  4. PAT甲级真题 1018 A+B in Hogwarts--python解法

    PAT甲级真题 1018 A+B in Hogwarts 提交:2638 通过:1559 通过率:59% If you are a fan of Harry Potter, you would kno ...

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

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

  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. 【PTA-A】1091 Acute Stroke (30 分)(BFS、队列)

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

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

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

最新文章

  1. ACCP学习旅程之-----基础篇
  2. linux伙伴系统算法,Linux伙伴系统(三)--分配
  3. [Android Pro] 终极组件化框架项目方案详解
  4. 粮草先行——Android折叠屏开发技术点番外篇之运行时变更处理原则
  5. vue项目token放在哪里_关于vue动态菜单的那点事
  6. HDFS的特性以及如何保证数据的一致性
  7. cd-rom门锁定什么意思_CD-ROM XA的完整格式是什么?
  8. 作为一个程序员,CPU的这些硬核知识你必须会!
  9. sqlite3用python家外键_Django/Sqlite3为带有外键的模型添加一行
  10. 嵌入式linux工程师 考试,嵌入式Linux工程师常见笔试题.doc
  11. ISIS网络配置方法
  12. 解决dev控件版本过期问题
  13. 学习bert过程中的思考,少走弯路
  14. matlab控制图像的边界(margin),subplot的间距(gap)
  15. 软件工程:软件开发生命周期 (SDLC)
  16. wdr7660虚拟服务器设置,TP-Link TL-WDR7660手机怎么设置?
  17. 大文件打包压缩成的几个小文件怎么解压?
  18. 国产积木---克尔维特(多图流量预警)
  19. 欧姆龙PLC远程上下载实际操作分享
  20. 删除word前面几页的页眉 保留后面的页眉

热门文章

  1. Android中的观察者DataSetObservable和DataSetObserver
  2. 本周没有学习,估计用脑过度...
  3. django项目基础
  4. 《信息存储与管理(第二版):数字信息的存储、管理和保护》—— 2.1 应用...
  5. linux基础-权限管理,手工添加用户,umask,bash配置文件
  6. 路径找不到时该怎么解决
  7. Android 实现图片画画板
  8. form表单target的用法 替代window.open
  9. [SAP ABAP开发技术总结]ABAP调优——Open SQL优化
  10. 微软警告:Office 已遭IE RCE 新0day 攻击