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 ...
随机推荐
- Spring+SpringMVC+MyBatis整合(easyUI、AdminLte3)
实战篇(付费教程) 花了几天的时间,做了一个网站小 Demo,最终效果也与此网站类似.以下是这次实战项目的 Demo 演示. 登录页: 富文本编辑页: 图片上传: 退出登录: SSM 搭建精美实用的管 ...
- SpringBoot日记——任务处理 之 异步、定时、邮件
---恢复内容开始--- 直接步入正题. 异步任务 异步任务比较简单,只需要两个注解就可以搞定,我们直接来看如何使用: 1.创建一个service,带上@EnableAsync,就是开启异步任务的注解 ...
- kill方法
删除磁盘上的文件. 语法 Kill 路径名 所需的_路径名_参数是一个字符串表达式,指定要删除的一个或多个文件名. _Pathname_可能包括驱动器和目录或文件夹. 例子删除当前路径下的TXT文档 ...
- MFS+Keepalived双机高可用热备方案操作记录
基于MFS的单点及手动备份的缺陷,考虑将其与Keepalived相结合以提高可用性.在Centos下MooseFS(MFS)分布式存储共享环境部署记录这篇文档部署环境的基础上,只需要做如下改动: 1) ...
- let命令和块级作用域
学习了阮一峰老师的ES6,http://es6.ruanyifeng.com/,收益良多. 一.let命令1.概念:let命令用于声明变量,和var类似,但是使用let命令所声明的变量只有在该变量所在 ...
- personal project
words count program 统计文本文件的字符数,单词数和行数. 实现一个统计程序,他能正确的统计程序文件中的字符数,单词数和行数. 源码链接 https://github.com/sup ...
- 关于hash冲突的解决
分离链接法:public class SeparateChainingHashTable<AnyType>{ private static final int DEFAULT_TABLE_ ...
- navicat有数据额结构同步
这个功能可能检查两个库的表结构异同,进行表结构构同步,可以生成同步语句. 比如在测试环境表中新增了字段,可以通过这个工具进行表结构同步.
- servlet请求转发
来源:http://www.2cto.com/kf/201610/554591.html 请求转发:Servlet(源组件)先对客户请求做一些预处理操作(数据处理),然后把请求转发给其他Web组件(目 ...
- 实战框架ABP
abp及实战框架概述 接触abp也快一年了,有过大半年的abp项目开发经验,目前项目中所用的abp框架版本为0.10.3,最新的abp框架已经到了1.4,并且支持了asp.net core.关于abp ...