PAT_A1091#Acute Stroke
Source:
Description:
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, Land 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 (≤) 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
Keys:
- 广度优先搜索(Breadth First Search)
Attention:
- 4,5测试点用递归会爆栈(段错误)
Code:
/*
time: 2019-08-26 17:10:21
problem: PAT_A1091#Acute Stroke
AC: 36:38 题目大意:
给出脑部各层的切片,患病几率与连续病变区域的数量有关,计算患病区域数量
输入:
第一行给出,各层的长度M<=1286和宽度N<=128,层数L<=60,患病阈值T(连续病变区域>=T时患病)
接下来L行,给出各层的信息,1病变,0正常
输出:
打印患病的病变区域数量 基本思路:
BFS统计各个块的有效结点数
*/
#include<cstdio>
#include<queue>
using namespace std;
const int L=,M=,N=;
struct node
{
int x,y,z;
};
int l,m,n,t,cnt,sum=,grap[L][M][N],vis[L][M][N];
int X[]={,-,,,,},Y[]={,,,-,,},Z[]={,,,,,-}; void BFS(int z,int x, int y)
{
grap[z][x][y]=;
queue<node> q;
q.push(node{x,y,z});
while(!q.empty())
{
node r = q.front();
q.pop();cnt++;
for(int i=; i<; i++)
{
int u=r.x+X[i],v=r.y+Y[i],w=r.z+Z[i];
if(u>=&&u<m&&v>=&&v<n&&w>=&&w<l)
if(grap[w][u][v]==)
{
grap[w][u][v]=;
q.push(node{u,v,w});
}
}
}
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE scanf("%d%d%d%d", &m,&n,&l,&t);
for(int k=; k<l; k++)
for(int i=; i<m; i++)
for(int j=; j<n; j++)
scanf("%d", &grap[k][i][j]);
for(int k=; k<l; k++)
for(int i=; i<m; i++)
for(int j=; j<n; j++)
if(grap[k][i][j]==)
{
cnt=;
BFS(k,i,j);
if(cnt>=t)
sum+=cnt;
}
printf("%d", sum); return ;
}
PAT_A1091#Acute Stroke的更多相关文章
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- PAT1091:Acute Stroke
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- A1091. Acute Stroke
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
- PAT 1091 Acute Stroke [难][bfs]
1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...
- pat1091. Acute Stroke (30)
1091. Acute Stroke (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One impo ...
- 1091 Acute Stroke (30)(30 分)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT 1091. Acute Stroke (bfs)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
随机推荐
- Windows-WAMP搭建与配置
使用 WampServer 整合软件包进行 WAMP 环境搭建 WampServer 是一款由法国人开发的 Apache Web 服务器.PHP 解释器以及 MySQL 数据库的整合软件包.免去了开发 ...
- python中输入多个数字(代码实现)
不多说,直接上代码: list1 = [] #定义一个空列表 str1 = input("请输入数值,用空格隔开:") # list2 = str1.split(" &q ...
- prim算法【最小生成树1】
适用范围:要求无向图 prim算法(读者可以将其读作“普里姆算法”)用来解决最小生成树问题, 其基本思想是: ·对图G(VE)设置集合S,存放已被访问的顶点, ·然后每次从集合V-S中选择与集合S的最 ...
- Linux 常用指令总结
一. 与时间有关的参数: 1.find 基本语法参数如下: find [PATH] [option] [action] -mtime n : n为数字,意思为在n天之前的“一天内”被更改过的文件: - ...
- CSS Sprites技术原理和使用
在分析各个网站的CSS时,我们经常可以看到一些网站有很多的元素共享了一张背景图片,而这张背景图片包含了所有这些元素需要的背景,这种技术就叫做CSS Sprites. 淘宝的css sprites ...
- gitlab+gitlab-ci+docker自动化部署
导言 本次测试用的是gitlab-ci,单纯与gitlab搭配而言,gitlab-ci较jenkins更加一体,顺畅. 主机1:192.168.100.151 gitlab 主机2:192.168.1 ...
- java.sql.BatchUpdateException: ORA-01861: 文字与格式字符串不匹配
解决: to_date(#runtime#,'yyyy-MM-dd HH24:mi:ss'), <!-- 执行时间:DATE -->
- openses机制
openses 大体结构解读 页面html与相关php文件的定位 点击界面,查看出现的url 例如: http://localhost/opensns/index.php?s=/people/inde ...
- 每天一个Linux常用命令 cat命令
在Linux系统中,cat命令是一个文本输出命令,通常用来查看某个文档的内容.它有如下三个功能: 1.一次性显示整个文件 如:查看/etc/initab文件,可以使用命令:cat/etc/initta ...
- dill:解决python的“AttributeError: Can't pickle local object”及无法pickle lambda函数的问题
python的pickle是用来序列化对象很方便的工具,但是pickle对传入对象的要求是不能是内部类,也不能是lambda函数. 比如尝试pickle这个内部类: 结果会报错AttributeErr ...