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. Redis闲谈(1):构建知识图谱

    场景:Redis面试 (图片来源于网络) 面试官: 我看到你的简历上说你熟练使用Redis,那么你讲一下Redis是干嘛用的? 小明: (心中窃喜,Redis不就是缓存吗?)Redis主要用作缓存,通 ...

  2. dnSpy进行反编译修改并编译运行EXE或DLL

    dnSpy对目标程序(EXE或DLL)进行反编译修改并编译运行 本文为原创文章.源代码为原创代码,如转载/复制,请在网页/代码处明显位置标明原文名称.作者及网址,谢谢! 本文使用的工具下载地址为: h ...

  3. linux下网卡绑定

    网卡绑定的作用:1.冗余,防止单点故障 2.防止传输瓶颈 1.交换机端口绑定: system-view link-aggregation group 1 mode manual 比如把端口1和2进行绑 ...

  4. Cannot create __weak reference in file using manual reference counting

    Xcode更新到7.3后会出现NSObject+MJProperty.h报Cannot create __weak reference in file using manual reference c ...

  5. phthon 基础 7.3 logging 日志模块

    一. logging 的使用 日志是我们排查问题的关键利器,写好日志记录,当我们发生问题时,可以快速定位代码范围进行修改.python有给我们开发者提供好的日志模块,下面我们就来介绍一下logging ...

  6. COGS1817. [WC2013]糖果公园

    1817. [WC2013]糖果公园 ★★★☆   输入文件:park.in   输出文件:park.out   简单对比时间限制:8 s   内存限制:512 MB [题目描述] Candyland ...

  7. Linq Group By 多个字段

    var counts = dal.QueryStatisticsCount(condition); var result = from p in counts group p by new { Auc ...

  8. serve-index用法、实现原理(源码解读)

    本文主要讲解serve-index的用法和实现原理(源代码分析). 一 说明 serve-index的功能是将文件夹中文件列表显示到浏览器中. serve-index是一个NodeJS模块,可以通过N ...

  9. Hadoop实战-Flume之自定义Sink(十九)

    import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...

  10. php总结8——mysql函数库、增删改

    8.1 mysql函数库 php的函数   .php中用来操作mysql函数库的函数 常用函数 mysql_connect("主机名称/ip","用户名",&q ...