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 ...
随机推荐
- javascript实现继承的六种方式
/*实现继承的六种方式*/ /*1.扩展原型对象的方法实现继承*/ function Foo1(){} //在Foo1函数上扩展一个fn1方法,由构造函数创建的对象都具有fn1这个方法 Foo1. ...
- Rust <4>:所有权、借用、切片
tips:栈内存分配大小固定,访问时不需要额外的寻址动作,故其速度快于堆内存分配与访问. rust 所有权规则: 每一个值在任意时刻都有且只有唯一一个所有者 当所有者离开作用域时,这个值将被丢弃 所有 ...
- 搭建RAID10(5块硬盘)过程并模拟其中一块硬盘损坏
首先:RAID 10,实际是将RAID 0和RAID 1标准结合的产物,在连续地以位或字节为单位分割数据并且并行读/写多个磁盘的同时,为每一块磁盘作磁盘镜像进行冗余.它的优点是同时拥有RAID 0的超 ...
- Linux(四)—— 项目部署与ansible自动化部署
目录 项目部署与ansible自动化部署 一.项目部署 二.ansible自动化部署(python自动化运维) 1.安装ansible 2.ansible例子 3.ansible自动化部署nginx ...
- UVA1152_4 Values whose Sum is 0
中途相遇法,这题目总结后我感觉和第一篇博客很像,他们都取了中间,也许这就是二分的魅力吧 这题题意就是从ABCD四个集合中选四个元素使他们的和为0 题意很简单,但是实现起来很容易超时,不能一个一个枚举 ...
- TP5.1/TP框架的访问控制,访问不存在的模块、控制器、方法等控制
TP框架的访问控制,默认模块.控制器.方法等 在tp框架中,config文件夹下的app.php文件可以设置默认的空模块名,默认的空控制器名. 举例:以上项目中有admin.common.api.er ...
- overflow:hidden失效
overflow:hidden失效 为了页面的健壮性,我们常常需要使用overflow:hidden.有时候是为了防止布局被撑开,有时候是为了配合其它规则实现文字截断,还有时候纯粹是为了创建块级上下文 ...
- JSON Web Token (JWT),服务端信息传输安全解决方案。
JWT介绍 JSON Web Token(JWT)是一种开放标准(RFC 7519),它定义了一种紧凑独立的基于JSON对象在各方之间安全地传输信息的方式.这些信息可以被验证和信任,因为它是数字签名的 ...
- 神奇,教你用随机数打印hello world
下面是一段随机数程序. public static void main(String[] args) { System.out.println(randomString(-229985452) + & ...
- python 3和python 2 的不同之 f - strings
python3.6版本及以上版本才能使用 f "{}{}{}" f-string 格式化输出
