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
就是求连通区域,如果连通区域内1的个数少于t就不算再内,计算总的1有多少,数有点大,容易内存超限,好在每个数不是0就是1,是确定的范围,可以选占内存小的数据类型。bfs求。用dfs最后两个点爆了。。。代码:
#include <stdio.h>
#include <stdlib.h>
struct pos {int x,y,z;
}q[10000],temp;
char mp[60][1300][130],vis[60][1300][130];
int n,m,l,t,all;
int dir[6][3] = {0,0,1,0,1,0,1,0,0,0,0,-1,0,-1,0,-1,0,0};
int bfs(int x,int y,int z) {q[0].x = x,q[0].y = y,q[0].z = z;int head = 0,tail = 1,sum = 1;while(head != tail) {for(int i = 0;i < 6;i ++) {int tx = q[head].x + dir[i][0];int ty = q[head].y + dir[i][1];int tz = q[head].z + dir[i][2];if(tx < 0 || ty < 0 || tz < 0 || tx >= l || ty >= n || tz >= m)continue;if(vis[tx][ty][tz] || !mp[tx][ty][tz])continue;vis[tx][ty][tz] = 1;sum ++;temp.x = tx,temp.y = ty,temp.z = tz;q[tail ++] = temp;tail %= 10000;}head ++;head %= 10000;}return sum;
}
int main() {scanf("%d%d%d%d",&n,&m,&l,&t);for(int i = 0;i < l;i ++) {for(int j = 0;j < n;j ++) {for(int k = 0;k < m;k ++) {scanf("%d",&mp[i][j][k]);}}}for(int i = 0;i < l;i ++) {for(int j = 0;j < n;j ++) {for(int k = 0;k < m;k ++) {if(vis[i][j][k] || !mp[i][j][k])continue;vis[i][j][k] = 1;int sum = bfs(i,j,k);if(sum >= t)all += sum;}}}printf("%d",all);
}

转载于:https://www.cnblogs.com/8023spz/p/9281287.html

1091 Acute Stroke (30)(30 分)相关推荐

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

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

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

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

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

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

  5. 1091 Acute Stroke (PAT甲级)

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

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

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

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

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

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

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

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

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

最新文章

  1. 使用函数求两个整数的最大公约数和最小公倍数
  2. C语言实例第3期:在控制台打印出著名的杨辉三角
  3. springmvc执行流程(简述易懂)
  4. 循环神经网络(RNN)相关知识
  5. x264_macroblock_cache_load()
  6. phpcms移动端和pc端_移动端调试大法
  7. json 插入数据_Power BI数据回写SQL Server(2)——存储过程一步到位
  8. MonoRail学习笔记十八:在VM中可以使用哪些系统变量
  9. 年轻人逃离推荐算法围城:老年版App,用着真香
  10. 本页不但包含安全的内容,也包含不安全的内容
  11. Atitit 个人信息数据文档知识分类
  12. 基于ffmpeg+SDL的加密视频播放器的开发(一)
  13. Mandelbrot集Julia集分形的MATLAB实现(分形艺术)
  14. Vue入门 computer计算属性
  15. (面试)Springboot的启动流程
  16. golang协程goroutine
  17. 接口测试(一)--soapui实践
  18. 酒店网站建设需要多少钱
  19. 抗锯齿下采样(Anti-aliasing/down-sampling)-python-numpy 实现
  20. (sdau) Summary of the third week.

热门文章

  1. allpairs使用方法_软件测试|正交试验测试用例设计方法
  2. python 多进程 requests_python多进程(二)
  3. 语言 读ini文件_让C语言的调试更加高大上
  4. Android开发究竟该如何学习,含泪整理面经
  5. 基于Pytorch再次解读DenseNet现代卷积神经网络
  6. 【深度学习】基于Torch的Python开源机器学习库PyTorch概述
  7. 【深度学习】深度神经网络框架的INPUT PROCESS
  8. Android移动开发之【Android实战项目】Recyclerview添加花色分割线
  9. php admin配置my sql,安装Mysqlphpadmin
  10. react 下拉选项自动滚动到可视区域