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 ...
随机推荐
- Python-str-操作-6
#字符串的索引与切片 s = 'ABCDLSESRF' #索引 s1 = s[0] print(s1) s2 = s[2] print(s2) s3 = s[-1] print(s3) s4 = s[ ...
- 《Linux内核分析》第四周学习总结
<Linux内核分析>第四周学习总结 ——扒开系统调用的三层皮 姓名:王玮怡 学号:20135116 理论总结部分: 第一节 用户态.内核 ...
- 冲刺Two之站立会议10
今天是最后一次站立会议,我们为自己软件最终版的发布进行了讨论,针对项目开发过程中出现的问题进行了总结.并讨论了之后软件如何发布和推广.
- Timer定时执行
//定时器 public void timeTask(String hh,int n) {//hh="8:30:00",n=12 Timer timer = new Timer() ...
- 第三个Sprint ------第五天
显示计算对错代码 package com.app.senior_calculator; import java.math.BigDecimal; import java.util.EmptyStack ...
- 开源通用爬虫框架YayCrawler-页面的抽取规则定义
本节我将向大家介绍一下YayCrawler的核心-页面的抽取规则定义,这也是YayCrawler能够做到通用的主要原因之一.如果我要爬去不同的网站的数据,尽管他们的网站采用的开发技术不同.页面的结构不 ...
- HTML的input类型为hidden导致无法reset改字段的value问题
问题关键:根据HTML规范,hidden是非ui类元素,不接受用户处理.所以form的 reset并不影响它. http://stackoverflow.com/questions/6367793/w ...
- JQuery插件:图片上传本地预览插件,改进案例一则。
/* *名称:图片上传本地预览插件 v1.1 *作者:周祥 *时间:2013年11月26日 *介绍:基于JQUERY扩展,图片上传预览插件 目前兼容浏览器(IE 谷歌 火狐) 不支持safari *插 ...
- Docker(十六)-Docker的daemon.json的作用
docker安装后默认没有daemon.json这个配置文件,需要进行手动创建.配置文件的默认路径:/etc/docker/daemon.json 一般情况,配置文件 daemon.json中配置的项 ...
- [转帖] “王者对战”之 MySQL 8 vs PostgreSQL 10
原贴地址:https://www.oschina.net/translate/showdown-mysql-8-vs-postgresql-10?lang=chs&page=2# 英文原版地址 ...