A1091. Acute Stroke
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
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int data[][][], inqu[][][];
int M, N, L, T;
int X[] = {,-,,,,}, Y[] = {,,,-,,}, Z[] = {,,,,,-};
typedef struct NODE{
int x, y, z;
}node;
int judge(node nd){
if(nd.x < || nd.x >= M || nd.y < || nd.y >= N || nd.z < || nd.z >= L)
return ;
else if(inqu[nd.z][nd.x][nd.y] == || data[nd.z][nd.x][nd.y] == )
return ;
else return ;
}
int bfs(int x, int y, int z){
queue<node> Q;
node nd = {x, y, z};
int cnt = ;
if(judge(nd) == ){
Q.push(nd);
inqu[nd.z][nd.x][nd.y] = ;
}
while(Q.empty() == false){
node temp = Q.front();
Q.pop();
cnt++;
node temp2;
for(int i = ; i < ; i++){
temp2.x = temp.x + X[i];
temp2.y = temp.y + Y[i];
temp2.z = temp.z + Z[i];
if(judge(temp2) == ){
inqu[temp2.z][temp2.x][temp2.y] = ;
Q.push(temp2);
}
}
}
if(cnt < T)
cnt = ;
return cnt;
}
int main(){
int ans = ;
scanf("%d%d%d%d", &M, &N, &L, &T);
for(int i = ; i < L; i++)
for(int j = ; j < M; j++)
for(int k = ; k < N; k++){
scanf("%d", &data[i][j][k]);
inqu[i][j][k] = ;
}
for(int i = ; i < L; i++)
for(int j = ; j < M; j++)
for(int k = ; k < N; k++)
ans += bfs(j, k, i);
printf("%d", ans);
return ;
}
总结:
1、本题题意:给出一个立方体,当连成一片的1的个数大于等于T时,这一块1被视为core。题目要求出大于T的1的总数量。注意是1的总数量而不是连片区的区数。使用三维数组存储数据,data[Z][X][Y],第一个Z记录层数,后面的X、Y才是每一层的数据。 可以使用bfs搜索,并记录连成一片的数量,当它>=T时,才返回本身的值,否则返回0。
2、使用inqu数组标记曾进入过队列的元素(不是访问过的元素),注意不要忘记给初始进入队列的元素坐标系,不要忘记检查第一个元素的合法性。
3、可以进入队列的条件:之前没有进入过的,且在合法的xyz区域内,且自身的data数据为1。
4、偏移数组:X[6] = {1,-1,0,0,0,0}, Y[6] = {0,0,1,-1,0,0}, Z[6] = {0,0,0,0,1,-1}; 可以使用循环来列举上下左右前后6个方位,初始化的方法是:当X为1或-1时,其它两个必须是0。
A1091. Acute Stroke的更多相关文章
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT A1091 Acute Stroke
对于坐标平面的bfs模板题~ #include<bits/stdc++.h> using namespace std; ; ][][]={false}; ][][]; int n,m,l, ...
- PAT_A1091#Acute Stroke
Source: PAT A1091 Acute Stroke (30 分) Description: One important factor to identify 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 ...
- 【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 ...
随机推荐
- 浅谈java反射机制
目录 什么是反射 初探 初始化 类 构造函数 属性 方法 总结 思考 什么是反射 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意 ...
- Sql_join left right
1.内连接inner join 只返回两张表中所有满足连接条件的行,即使用比较运算符根据每个表中共有的列的值匹配两个表中的行.(inner关键字是可省略的) ①传统的连接写法: 在FROM子句中列出所 ...
- 撰写POPUSH需求文档
不当家不知柴米贵,撰写了正规的软件需求文档才知道软件工程的复杂性 感谢@洪宇@王需@江林楠下午的加班加点,五个人正闷在406B奋斗中,加油!
- M1阶段个人总结
经过4周的开发,我们团队的第一阶段已经结束了. 这一个月来我由于其他事情较多,所以开发的工作主要交给了另外的三名同学. 我主要负责制定代码规范和工程结构,通过github来跟进项目进度,提供一些技术支 ...
- 【BUAA软件工程】第一次阅读作业
BUAA软件工程 第一次阅读作业 项目 内容 这个作业属于哪个课程? 北航软工 这个作业的要求在哪里? 第一次个人作业 我在这个课程的目标是? 学习高效严谨的软件工程开发过程,建立团队意识 这个作业在 ...
- 我的github地址 https://github.com/1010de/Test.git
构建之法老师叫交下任务学习github,经过一段时间的学习和了解,看介绍.看视频.看博客.初步认识到github的方便与好处. 自己试着去注册和使用github,已经慢慢学会了一些基本操作. ...
- mybaits拦截器+自定义注解
实现目的:为了存储了公共字典表主键的其他表在查询的时候不用关联查询(所以拦截位置位于mybaits语句查询得出结果集后) 项目环境 :springboot+mybaits 实现步骤:自定义注解——自定 ...
- 第三次Sprint
Not CHECKED OUT CHECKED OUT DONE!: SPRINT GOAL: BETA-READY 修改bug 完善界面
- 四则运算APP
1) N (Need 需求) 用户基本需求:随机生成四则运算,能自动判定对错,答错时能提示正确答案! 在这个基础上,我的创意: 多用户模式,能记录用户的答题情况(登陆功能) 分级挑战,按照不同的水 ...
- nodefs模块的使用demo
为什么要使用递归?因为stat本身就是一个异步的函数所有存在异步问题不能够进行循环遍历. 在使用该种方法时候需要注意的一点是必须要在箭头标记处进行数据数组的存取.否则会由于异步问题导致输出空或者其他问 ...