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 ...
随机推荐
- dubbo系列学习好文章
1. dubbo入门学习(一)-----分布式基础理论.架构发展以及rpc.dubbo核心概念 https://www.cnblogs.com/alimayun/p/10982650.html 2. ...
- IIS日志如何记录X-Forwarded-For
起因 最近因为某个站点的流量异常,需要统计一下服务器的来源IP,本来开一下IIS日志就能搞定的事儿,但不幸的是生产服务器使用F5做了负载均衡,IIS日志无法记录到真实IP,真实的IP在"x- ...
- QT的三种开发方式
最近在学习QT GUI,单纯使用C++硬编码的方式,直接是采用QWidget部件来做,而不是采用QT Designer做UI界面,也不是采用QML+Javascript.单纯使用C++硬编码的方式,缺 ...
- editplus 正则表达式 分组替换
editplus :zz正则表达式替换 /开头的api+换行符 替换为 /开头的api+空格 \1后有空格 editplus :zz正则表达式替换 行首两个数字+换行符 替换为 行首两个数字+空 ...
- Java中HashMap与ConcurrentHashMap的区别
从JDK1.2起,就有了HashMap,正如前一篇文章所说,HashMap不是线程安全的,因此多线程操作时需要格外小心. 在JDK1.5中,伟大的Doug Lea给我们带来了concurrent包,从 ...
- 关于Oracle中Sort Merge Join的改写
业务场景的问题,我们有一个刷CUBE的SQL,是Oracle环境,平时跑70多分钟, 但是最近突然不动了,这个SQL需要算累计值,比如年累计客户数量. 累计值是什么意思呢?我们使用下面的数据来说明问题 ...
- 【记录】linux中不同颜色代表的含义
下面是linux约定不同类型文件默认的颜色 白色:表示普通文件 蓝色:表示目录 绿色:表示可执行文件 红色:表示压缩文件 浅蓝色:链接文件 红色闪烁:表示链接的文件有问题 黄色:表示设备文件 灰色:表 ...
- 2018-8-10-win10-UWP-button
title author date CreateTime categories win10 UWP button lindexi 2018-08-10 19:16:53 +0800 2018-2-13 ...
- redis Sorted set 相关命令
- suffixes - 列出文件后缀。
DESCRIPTION [描述] 文件后缀与文件名之间以点(.)间隔,通常包括一个或多个字母. 我们用文件后缀来描述文件的内容.很多标准的实用程序,如编译器,以后缀来识别文件类型. make(1) 就 ...