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 ...
随机推荐
- R语言学习4:函数,流程控制,数据框重塑
本系列是一个新的系列,在此系列中,我将和大家共同学习R语言.由于我对R语言的了解也甚少,所以本系列更多以一个学习者的视角来完成. 参考教材:<R语言实战>第二版(Robert I.Kaba ...
- CSS 书写禅机
这是未来的趋势所向,如是我行. 注意:原文发表于 2017-9-6,随着框架不断演进,部分内容可能已不适用. CSS 日渐惹人憎恶. 究其原因颇多,归根结底,皆因 CSS 给人的感觉总是飘渺迷蒙.变幻 ...
- 【ZeyFraのJavaEE开发小知识01】@DateTimeFomat和@JsonFormat
@DateTimeFormat 所在包:org.springframework.format.annotation.DateTimeFormat springframework的注解,一般用来对Dat ...
- 第41天学习打卡(死锁 Lock synchronized与Lock的对比 线程协作 使用线程池)
死锁 多个线程各自占有一些共享资源,并且互相等待其他线程占有的资源才能运行,而导致两个或者多个线程都在等待对方释放资源,都停止执行的情形.某一个同步块同时拥有"两个以上对象的锁"时 ...
- 基于Hi3559AV100 RFCN实现细节解析-(1)VGS初介绍
下面随笔系列将对Hi3559AV100 RFCN实现细节进行解析,因为RFCN用到了VGS加框,因此本篇随笔将给出VGS视频图像子系统的具体说明,便于后面RFCN的细节实现说明. VGS 是视频图形子 ...
- sap2000v21安装教程(附详细安装步骤+中文安装包)
sap2000 v21是sap2000系列软件的全新版本,也是目前行业中的一款用于结构分析和设计的集成软件,该软件保持了原有产品的传统,具有完善.直观和灵活的界面,能够在交通运输.工业.公共事业.体育 ...
- 2020年12月-第02阶段-前端基础-CSS字体样式
CSS字体样式属性调试工具 应用 使用css字体样式完成对字体的设置 使用css外观属性给页面元素添加样式 1.font字体 1.1 font-size:大小 作用: font-size属性用于设置字 ...
- 使用egg.js开发后端API接口系统
什么是Egg.js Egg.js 为企业级框架和应用而生,我们希望由 Egg.js 孕育出更多上层框架,帮助开发团队和开发人员降低开发和维护成本.详细的了解可以参考Egg.js的官网:https:// ...
- 【Azure API 管理】APIM CORS策略设置后,跨域请求成功和失败的Header对比实验
在文章"从微信小程序访问APIM出现200空响应的问题中发现CORS的属性[terminate-unmatched-request]功能"中分析了CORS返回空200的问题后,进一 ...
- SpringMVC-06 Ajax
SpringMVC-06 Ajax Ajax 1.简介 AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 是一种在无 ...