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

就是求连通区域,如果连通区域内1的个数少于t就不算再内,计算总的1有多少,数有点大,容易内存超限,好在每个数不是0就是1,是确定的范围,可以选占内存小的数据类型。
bfs求。用dfs最后两个点爆了。。。
代码:
#include <stdio.h>
#include <stdlib.h>
struct pos {
int x,y,z;
}q[],temp;
char mp[][][],vis[][][];
int n,m,l,t,all;
int dir[][] = {,,,,,,,,,,,-,,-,,-,,};
int bfs(int x,int y,int z) {
q[].x = x,q[].y = y,q[].z = z;
int head = ,tail = ,sum = ;
while(head != tail) {
for(int i = ;i < ;i ++) {
int tx = q[head].x + dir[i][];
int ty = q[head].y + dir[i][];
int tz = q[head].z + dir[i][];
if(tx < || ty < || tz < || tx >= l || ty >= n || tz >= m)continue;
if(vis[tx][ty][tz] || !mp[tx][ty][tz])continue;
vis[tx][ty][tz] = ;
sum ++;
temp.x = tx,temp.y = ty,temp.z = tz;
q[tail ++] = temp;
tail %= ;
}
head ++;
head %= ;
}
return sum;
}
int main() {
scanf("%d%d%d%d",&n,&m,&l,&t);
for(int i = ;i < l;i ++) {
for(int j = ;j < n;j ++) {
for(int k = ;k < m;k ++) {
scanf("%d",&mp[i][j][k]);
}
}
}
for(int i = ;i < l;i ++) {
for(int j = ;j < n;j ++) {
for(int k = ;k < m;k ++) {
if(vis[i][j][k] || !mp[i][j][k])continue;
vis[i][j][k] = ;
int sum = bfs(i,j,k);
if(sum >= t)all += sum;
}
}
}
printf("%d",all);
}

1091 Acute Stroke (30)(30 分)的更多相关文章

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

    1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

  2. PAT 1091 Acute Stroke [难][bfs]

    1091 Acute Stroke (30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the ...

  3. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  4. PAT甲级——A1091 Acute Stroke【30】

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

  5. PAT 1091. Acute Stroke (bfs)

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

  6. 1091 Acute Stroke

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

  7. 【PAT甲级】1091 Acute Stroke (30 分)(BFS)

    题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...

  8. PAT (Advanced Level) 1091. Acute Stroke (30)

    BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...

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

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

随机推荐

  1. 【甘道夫】Ubuntu14 server + Hadoop2.2.0环境下Sqoop1.99.3部署记录

    第一步.下载.解压.配置环境变量: 官网下载sqoop1.99.3 http://mirrors.cnnic.cn/apache/sqoop/1.99.3/ 将sqoop解压到目标文件夹,我的是 /h ...

  2. 应对ie双外边距,不使用hack

    1.在浮动元素内层加一层div 2.使用不浮动的内层外边距来定义距离 ie在浮动时,并且使用外边距,会产生双倍外边距.

  3. flash插件使用外部数据的方法

    使用xml保存需要改变的数据,如轮播图的图片路径,也可以在xml中指定数据库地址等

  4. 加入 centos 右键 terminal

    centos6.2以上默认右键都没有terminal,现加入方法 例如以下 1>  yum -y install nautilus-open-terminal 2> shutdown -r ...

  5. OpenCV 中的三大数据类型:CvMat 类型

    前言 本文将介绍 OpenCV 中的矩阵结构 CvMat 并提供几个很常用的矩阵使用方法. 更多的矩阵处理函数还请参阅相关资料. CvMat 的类型定义 typedef struct CvMat { ...

  6. Android模糊效果总结

    1. 软件模糊 用软件的方法.利用cpu计算,无sdk版本号要求. 效果图: 关键模糊代码 github链接 原文 链接 译文 链接 演示样例 代码 本文地址 :http://blog.csdn.ne ...

  7. iOS7 文本转语音 AVSpeechSynthesizer -转载-

    http://www.cnblogs.com/qingjoin/p/3160945.html iOS7 的这个功能确实不错.我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音! Xco ...

  8. python MySQLdb Windows下安装教程及问题解决方法(python2.7)

    使用python访问mysql,需要一系列安装 linux下MySQLdb安装见  Python MySQLdb在Linux下的快速安装http://www.jb51.net/article/6574 ...

  9. ClassNotFoundException Log

    Studio 运行时异常: Error:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation fail ...

  10. python 中读取excel

    第一步:  先下载一个xlrd 包 # pip install xlrd import xlrd from datetime import date, datetime file = '学生信息表.x ...