1091 Acute Stroke (30)(30 分)
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 分)的更多相关文章
- 【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 ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- PAT甲级——A1091 Acute Stroke【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 ...
- 1091 Acute Stroke
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 【PAT甲级】1091 Acute Stroke (30 分)(BFS)
题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...
- PAT (Advanced Level) 1091. Acute Stroke (30)
BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...
- PAT甲题题解-1091. Acute Stroke (30)-BFS
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
随机推荐
- 关于iOS Tabbar的一些设置
事实上iOS Tabbar的可定制性很高,我们没有必要反复造轮子,以下是笔者收集的一些tabbar的经常使用设置.希望对大家有所帮助. 设置tabbar选中颜色 iOS7设置例如以下: [self.t ...
- C语言 结构体篇
结构体:是一种构造类型 它是由若干成员组成的 其中每一个成员都可以是一个基本数据类型或者又是一个构造类型 定义结构体变量后,系统就会为其自动分配内存 为了便于更大的程序便于修改和使用 常常将结构体类 ...
- conda清华源 pip 清华源ubuntu 清华镜像 R代理以及包的安装
vim ~/.condarc channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/ - https:// ...
- jdbcTemplaate queryForObject的两个易混淆的方法
JdbcTemplate中有两个可能会混淆的queryForObject方法: 1. Object queryForObject(String sql, Object[] args, Class ...
- leetCode 47.Permutations II (排列组合II) 解题思路和方法
Permutations II Given a collection of numbers that might contain duplicates, return all possible un ...
- JAVA使用并行流(ParallelStream)时要注意的一些问题
https://blog.csdn.net/xuxiaoyinliu/article/details/73040808
- eclipse中三大利器
eclipse中两大利器: 首先说下用eclipse开发工具.进行java代码,开发的时候,我们开发完成以后.需要测试.大部分我们用Junit测试工具.可是内部的代码覆盖率.和结构我们看的不是那么详细 ...
- RRDTool详解(转)
原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处.作者信息和本声明.否则将追究法律责任.http://freeloda.blog.51cto.com/2033581/1307492 大纲 ...
- Mysql 索引增加与删除
[1]索引 索引,通俗理解,即目录. 之前说过,计算机是对现实世界的模拟.目录应用在数据库领域,即所谓的索引. 目录的作用显而易见,所以建立索引可以大大提高检索的速度. 但是,会降低更新表的速度,如对 ...
- 不错的iOS相关的主页或站点 (更新于14-06-22)
近期一直没事在翻一些站点看看资料学习下. 推荐几个不错的站点: http://www.raywenderlich.com/ 这个站点有各种各样的教程,可惜是大部分都是英文教程,只是阅读起来还好.每 ...