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,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
随机推荐
- ORCAD中的一些操作小技巧
1.ORCAD中改变元器件和文本字体颜色的命令: 打开在 View -> Toolbar -> Command Window.然后圈选文字(可复选),然后到 Command Window ...
- jQuery--基础(操作标签)
jQuery-样式操作 .css() 可以直接使用来获取css的值 .css("color") 使用方法,如果想给查找到的标签添加样式: .css("colo ...
- ServletContext读取配置文件
package servlet; import java.io.FileInputStream;import java.io.IOException;import java.io.InputStrea ...
- 畅通project再续 HDU杭电1875 【Kruscal算法 || Prim】
Problem Description 相信大家都听说一个"百岛湖"的地方吧.百岛湖的居民生活在不同的小岛中.当他们想去其它的小岛时都要通过划小船来实现.如今政府决定大力发展百岛湖 ...
- 在dev目录创建一个字符设备驱动的流程
1.struct file_operations 字符设备文件接口 1: static int mpu_open(struct inode *inode, struct file *file) 2: ...
- 【nginx】关于Nginx的一些优化(突破十万并发)
nginx指令中的优化(配置文件) worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数. worker_cpu_affinity 00000001 00 ...
- Boost.Asio c++ 网络编程翻译(11)
*_at方法 这些方法在一个流上面做随机存取操作.你来指定read和write操作从什么地方開始(offset): async_read_at(stream, offset, buffer [, co ...
- Net中的代码规范工具及使用
Net中的代码规范工具及使用 https://www.cnblogs.com/selimsong/p/9209254.html 上一篇文章介绍了编码标准中一些常用的工具,本篇就具体来介绍如何使用它们来 ...
- linux 经常使用命令
帮助信息 ./configure -help|grep mysql 安装php ./configure --prefix=/usr/local/fastphp --with-mysql=mysqlnd ...
- 【Caffe】源码解析----caffe.proto (转载)
分析caffe源码,看首先看caffe.proto,是明智的选择.好吧,我不是创造者,只是搬运工. 原文地址:http://blog.csdn.net/qq_16055159/article/deta ...