1091. Acute Stroke (30)

时间限制
400 ms

内存限制
65536 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

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


提交代码

题意:有l 片slices 每片上由 n*m个 像素点, l 片slices是按次序从下往上或者从上往下, 三维空间里上下左右相邻的算一块,一块至少要包含t个像素点才能计入总数,求总数

dfs就好了,不过最后两个案例数据量比较大,会爆栈,要用队列来写

#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
int m,n,l,T,volume,totVol;
bool mapp[70][1300][130];
struct Point
{int z,x,y;Point(){}Point(int z,int x,int y):z(z),x(x),y(y){}
};
void dfs(int z,int x,int y)
{//此方法最后两个案例段错误,原因是递归深度会大于100000if(mapp[z][x][y]){volume++;mapp[z][x][y]=false;if(z>0)dfs(z-1,x,y);if(z+1<l)dfs(z+1,x,y);if(x>0)dfs(z,x-1,y);if(x+1<m)dfs(z,x+1,y);if(y>0)dfs(z,x,y-1);if(y+1<n)dfs(z,x,y+1);}
}
void dfs_queue(int i,int j,int k)
{if(!mapp[i][j][k])return;queue<Point>p;p.push(Point(i,j,k));while(!p.empty()){int z=p.front().z;int x=p.front().x;int y=p.front().y;p.pop();if(mapp[z][x][y]){mapp[z][x][y]=false;volume++;if(z>0)p.push(Point(z-1,x,y));if(z+1<l)p.push(Point(z+1,x,y));if(x>0)p.push(Point(z  ,x-1,y));if(x+1<m)p.push(Point(z,x+1,y));if(y>0)p.push(Point(z,x,y-1));if(y+1<n)p.push(Point(z,x,y+1));}}
}
int main()
{while(~scanf("%d%d%d%d",&m,&n,&l,&T)){int x;for(int i=0;i<l;i++){for(int j=0;j<m;j++){for(int k=0;k<n;k++){scanf("%d",&x);if(x)mapp[i][j][k]=true;else mapp[i][j][k]=false;}}}totVol=0;for(int i=0;i<l;i++){for(int j=0;j<m;j++){for(int k=0;k<n;k++){volume=0;//  dfs(i,j,k);
                    dfs_queue(i,j,k);if(volume>=T)totVol+=volume;}}}printf("%d\n",totVol);}return 0;
}

PAT1091

转载于:https://www.cnblogs.com/kylehz/p/4137141.html

pat1091. Acute Stroke (30)相关推荐

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

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

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

  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 分)【难度: 一般 / bfs】

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

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

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

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

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

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

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

最新文章

  1. 全面讲解电脑主板-图文
  2. C++ algorithm中find系列函数总结
  3. 配置ADB到Windows环境变量
  4. EasyMock 使用方法与原理剖析
  5. Spring MVC开发RESTful风格的URI
  6. python对话机器人框架_长篇文讲解:使用Python AIML搭建聊天机器人的方法示例(收藏)...
  7. (王道408考研数据结构)第六章图-第四节1:最小生成树之普利姆算法(思想、代码、演示、答题规范)
  8. Spring从入门到入土——Bean的作用域与生命周期
  9. speedtest命令行linux,Linux或者Mac下命令行speedtest测试网络速度
  10. c语言圆形体体积计算器,圆的半径计算软件
  11. 常用度量--MAE(平均绝对误差)和RMSE(均方根误差)
  12. Eclipse安装反编译工具Eclipse Class Decompiler:实现不下载源码,查看源文件
  13. android sim卡pin,如何设置手机的SIM卡的PIN码?
  14. 2020美容师(初级)模拟考试及美容师(初级)复审模拟考试
  15. [BUAA OO Unit 2 HW8] 第二单元总结
  16. Thinkphp5 php会员实现单点登录
  17. 南开大学计算机党支部书记,程莉莉
  18. Enable Geolocation in a WebView (Android)
  19. 从《进化/运维技术变革与实践探索》看运维体系建设与个人成长
  20. 大数据毕业设计 机器学习文本聚类系统 - 舆情分析

热门文章

  1. [导入]基于Spring+zk的WebDisk系统研究.pdf(462.84 KB)
  2. 深入biztalk消息以及消息订阅发布路由机制(四)-消息的轮询和执行
  3. LeetCode(620)——有趣的电影(MySQL)
  4. 函数中的 arguments
  5. 【JavaScript】查漏补缺 —数组中filter()方法
  6. HTML之表单的基本知识
  7. 装修好的房子多久能住 入住需要注意什么?
  8. 一些关于直播间人货场的打造干货,直播电商新手必须要了解人货场的概念
  9. 做人不能太心软,这三件事上,越狠心就越受益
  10. 公司电脑可以做无盘系统吗?怎么优化速度?