1091 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×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
题意:
每一个二维矩阵代表一个切片,矩阵中“1”代表病变,“0”代表没有发生病变,只有连在一起的病变块的数目达到一定值时才被计入其中。输出有多少病变。
思路:
刚开始想到的是用模拟的方法来解决这道题,但是做到搜索的时候就没办法再往下做了。然后看了一下别人的代码,发现题目可以抽象成一个三维矩阵的BFS。
Code:
#include<iostream>
#include<vector>
#include<queue> using namespace std; int m, n, l, t;
int count = 0, rang = 0, total = 0;
vector<vector<vector<int> > > matrix;
vector<vector<vector<int> > > visited;
vector<int> dir = {1, 0, 0, -1, 0, 0, 1, 0}; bool inMatrix(int i, int j, int k) {
if (i >= 0 && i < l && j >= 0 && j < m && k >= 0 && k < n)
if (matrix[i][j][k] == 1 && visited[i][j][k] == 0) return true;
return false;
} void BFS(int x, int y, int z) {
visited[x][y][z] = 1;
count++;
for (int i = 0; i < 6; ++i) {
if (inMatrix(x+dir[i], y+dir[i+1], z+dir[i+2]))
BFS(x+dir[i], y+dir[i+1], z+dir[i+2]);
}
} int main() {
cin >> m >> n >> l >> t; matrix = vector<vector<vector<int> > >(l, vector<vector<int> >(m, vector<int>(n, 0)));
visited = vector<vector<vector<int> > >(l, vector<vector<int> >(m, vector<int>(n, 0))); for (int i = 0; i < l; ++i) {
for (int j = 0; j < m; ++j) {
for (int k = 0; k < n; ++k) {
int p;
cin >> p;
matrix[i][j][k] = p;
}
}
}
for (int i = 0; i < l; ++i) {
for (int j = 0; j < m; ++j) {
for (int k = 0; k < n; ++k) {
count = 0;
if (visited[i][j][k] == 0 && matrix[i][j][k] == 1)
BFS(i, j, k);
if (count >= t) total += count;
}
}
} cout << total << endl; return 0;
}
提交之后有两组数据显示“Segmentation Fault”。
1091 Acute Stroke的更多相关文章
- 【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 ...
- 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 (bfs)
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- PAT (Advanced Level) 1091. Acute Stroke (30)
BFS求连通块.递归会爆栈. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...
- PAT甲级1091 Acute Stroke【三维bfs】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072 题意: 求三维的连通块 思路: 简单b ...
- PAT甲题题解-1091. Acute Stroke (30)-BFS
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
- 【PAT甲级】1091 Acute Stroke (30 分)(BFS)
题意: 输入四个正整数M,N,K,T(K<=60,M<=1286,N<=128),代表每片的高度和宽度,片数和最小联通块大小.输出一共有多少个单元满足所在联通块大小大于等于T. tr ...
随机推荐
- E: Some index files failed to download. They have been**
转: E: Some index files failed to download. They have been** 问题描述: 当使用Dockerfile从包含cuda的镜像建立新的image的时 ...
- 剑指 Offer 48. 最长不含重复字符的子字符串 + 动态规划 + 哈希表 + 双指针 + 滑动窗口
剑指 Offer 48. 最长不含重复字符的子字符串 Offer_48 题目详情 解法分析 解法一:动态规划+哈希表 package com.walegarrett.offer; /** * @Aut ...
- 恭喜!Apache Hudi社区新晋两位Committer
1. 介绍 经过Apache Hudi项目委员会讨论及投票,向WangXiangHu和LiWei 2人发出Committer邀请,2人均已接受邀请并顺利成为Committer,也使得Apache Hu ...
- 如何快速的插入 100W数据到数据库,使用PreparedStatement 最快实现!
有时候,我们使用数据库的时候,如何快速的添加测试数据到数据库中,做测试呢,添加100W 数据,如果使用工具的话可能很慢,这里我推荐大家使用 PreparedStatement 预编译 去进行操作:单线 ...
- SpringMVC源码分析和启动流程
https://yq.aliyun.com/articles/707995 在Spring的web容器启动时会去读取web.xml文件,相关启动顺序为:<context-param> -- ...
- 一个C#开发编写Java框架的心路历程
前言 这一篇絮絮叨叨,逻辑不太清晰的编写Java框架的的一个过程,主要描述我作为一个java初学者,在编写Java框架时的一些心得感悟. 因为我是C#的开发者,所以,在编写Java框架时,或多或少会带 ...
- gtk---实现一个登录界面
输入框 如果在GTK+中需要输入一个字符串,可以使用输入框,这是一个单行的输入构件,可以用于输入和显示正文内容. 输入框的基本操作函数 1.gtk_entry_new(void); 这是新建一个输入框 ...
- x64dbg 条件断点相关文档
输入 字符格式 条件断点 Input When using x64dbg you can often use various things as input. Commands Commands ha ...
- 自动QQ邮箱发送邮件
语言:python 参考:https://www.runoob.com/python/python-email.html 前提: 1.QQ邮箱开启了SMTP服务 2.生成了授权码,这个授权码将作为自己 ...
- js--如何实现继承?
前言 学习过 java 的同学应该都知道,常见的继承有接口继承和实现继承,接口继承只需要继承父类的方法签名,实现继承则继承父类的实际的方法,js 中主要依靠原型链来实现继承,无法做接口继承. 学习 j ...