PAT甲级——A1091 Acute Stroke【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×N matrix, and the maximum resolution is 1286 by 128); L (≤) 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×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 <iostream>
#include <queue>
using namespace std;
struct Node
{
int x, y, z;
Node(int xx, int yy, int zz) :x(xx), y(yy), z(zz) {}
};
int M, N, L, T, res = ;
int direct[][] = { {-,,},{,,},{,-,},{,,},{,,-},{,,} };
bool G[][][];//遍历记录
int BFS(Node p)
{
int num = ;
queue<Node>q;
q.push(p);
G[p.x][p.y][p.z] = false;
while (!q.empty())
{
p = q.front();
q.pop();
++num;
for (int i = ; i < ; ++i)
{
int x = p.x + direct[i][];
int y = p.y + direct[i][];
int z = p.z + direct[i][];
if (x < M && x >= && y >= && y < N && z >= && z <= L && G[x][y][z])
{
q.push(Node(x, y, z));
G[x][y][z] = false;
}
}
}
return num;
}
int main()
{
cin >> M >> N >> L >> T;
for (int k = ; k < L; ++k)
for (int i = ; i < M; ++i)
for (int j = ; j < N; ++j)
cin >> G[i][j][k];
for(int i=;i<M;++i)
for(int j=;j<N;++j)
for(int k=;k<L;++k)
if (G[i][j][k])
{
int temp = BFS(Node(i, j, k));
if (temp >= T)
res += temp;
}
cout << res << endl;
return ;
}
PAT甲级——A1091 Acute Stroke【30】的更多相关文章
- PAT甲级1091 Acute Stroke【三维bfs】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072 题意: 求三维的连通块 思路: 简单b ...
- pat1091. Acute Stroke (30)
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 ...
- 1091. Acute Stroke (30)
题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...
- A1091. Acute Stroke
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 1091 Acute Stroke (30)(30 分)
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,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
随机推荐
- Spark Streaming的简单介绍
本文讲解Spark流数据处理之Spark Streaming.本文的写作时值Spark 1.6.2发布之际,Spark 2.0预览版也已发布,Spark发展如此迅速,请随时关注Spark Stream ...
- MapReduce1.0的缺陷
- WPF命令好状态刷新机制
https://blog.csdn.net/WPwalter/article/details/90344470 this.DispatcherInvoke(() => { System.Wind ...
- 【JZOJ6350】考试(test)
description analysis 对于\(n=0\)的点,直接模拟就好了 状压\(DP\),设\(f[i][j][S]\)表示到第\(i\)题.连续\(GG\)了\(j\)题.喝的饮料集合为\ ...
- JS请求服务器,并返回信息,请求过程中不需要跳转页面
js请求服务器,并返回信息,请求过程中不需要跳转页面 这个可以通过jQuery框架轻松实现,jQuery中包含多种ajax的请求方式,详细可以参考下对应 的API. 你上面定义的按钮类型是submit ...
- mysql查询语句对于为null和为空字符串给出特定值处理
SELECT if(IFNULL(filedName,"指定字符串")="","指定字符串",filedName) '重命名的字符名' FR ...
- echarts renderItem-在区间段内展示连续数据
一.需求背景: 贴图说明:要求数据在不同类型的区间段内展示. 二.实现思路及代码 实现方法: 利用echarts的自定义配置:option.series[i].type='custom'中的rende ...
- SpringCloud学习笔记(六):Feign+Ribbon负载均衡
简介 官网解释: http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign Feign是一个声明式WebS ...
- mui 上拉加载 实现分页加载功能
mui 上拉加载 实现分页加载功能,效果图: 分页功能(上拉加载): 1.引入需要的css.js文件 <link href="static/css/mui.css" rel= ...
- echars前端处理数据、pyechars后端处理数据
echars -- 后端给数据,前端根据数据做渲染 - echarts:https://www.echartsjs.com/zh/index.htmlhtml文件 <!DOCTYPE html& ...