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 ...
随机推荐
- [译]通往 Java 函数式编程的捷径
原文地址:An easier path to functional programming in Java 原文作者:Venkat Subramaniam 译文出自:掘金翻译计划 以声明式的思想在你的 ...
- 用JS制作一个信息管理平台(1)
首先,介绍一些需要用到的基本知识. [JSON] JSON是数据交互中,最常用的一种数据格式. 由于各种语言的语法都不相同,在传递数据时,可以将自己语言中的数组.对象等转换为JSON字符串. 传递之后 ...
- python报错问题解决:'ascii' codec can't encode character
之前部署了openstack虚拟化环境,有一天在使用nova list查看虚拟机的时候,突然报错!如下: [root@linux-node1 src]# nova listERROR (Unicode ...
- B. Heaters Div3
链接 [http://codeforces.com/contest/1066/problem/B] 分析 具体看代码,贪就完事了 代码 #include<bits/stdc++.h> us ...
- SoftwareEngineering Individual Project - Word frequency program
说实话前面c#实在没怎么学过.这次写起来感觉非常陌生,就连怎么引用名空间都忘记了.在经过恶补后还是慢慢地适应了. 1.项目预计用时: 构建并写出大概的数据结构,程序框架及模块: 30min 实现文件夹 ...
- 2017BUAA软工第0次作业
第一部分:结缘计算机 1. 你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? 我在上大学之前,其实一直就没怎么考虑过自己以后想要选什么专业,只知道一个大致的方向一定是理工科.毕竟大学之前, ...
- php中获取数据 php://input、$_POST与$GLOBALS['HTTP_RAW_POST_DATA']三者的区别
$_POST 只有Coentent-Type的值为application/x-www.form-urlencoded和multipart/form-data两种类型时,$_POST才能获取到数据. $ ...
- Bootstrap插件概述
前面的话 Bootstrap除了包含丰富的Web组件之外,如下拉菜单.按钮组.导航.分页等,还包括一些JavaScript的插件.插件为 Bootstrap 的组件赋予了“生命”.Bootstrap的 ...
- caffe实现多任务学习
Github: https://github.com/Haiyang21/Caffe_MultiLabel_Classification Blogs 1. 采用多label的lmdb+Slice L ...
- BZOJ2434[Noi2011]阿狸的打字机——AC自动机+dfs序+树状数组
题目描述 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机.打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母. 经阿狸研究发现,这个打字机是这样工作的: l 输入小 ...