目录
1,题目描述
题目大意
输入
补充
2,思路
数据结构
算法
3,AC代码
4,解题过程
第一搏
第二搏
第三搏
1,题目描述
Sample Input:
Sample Output:
题目大意
求出图片中每块(连通分量)1的个数,当个数超过阈(( ﹁ ﹁ ) ~→yu)值时,算作肿瘤,加入ans中;
- Two pixels areconnectedand hence belong to the same region if they share a common side :注意这里的pixel是像素点,不是slice,而是题目中的0/1;
输入
- 第一行:M,N,L(长宽高),T判断阈值 ;
- 剩余:给出L片中,每片(M* N个像素点)的像素点值;
补充
- 为了方便结构体赋予初值,故为结构体设计构造函数:详细用法参考@Esrevinud的笔记【C/C++ 结构体 构造函数】
2,思路
参考大佬@日沉云起【pat甲级1091. Acute Stroke (30 point(s))】
(三维M*N*L图形,BFS搜索。由于DFS是递归进行,深度过大时,可能出现溢出,BFS则是利用队列,不会出现这种情况)
数据结构
- int direction[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}}:方向矩阵,分别代表6个方向;
- bool graph[130][130][80]:存放三维图片;
- struct node{
int x, y, z;
node(int xx, int yy, int zz) : x(xx), y(yy), z(zz) {} // !!!构造函数 学到了
};像素点位置;
算法
- BFS算法:常规算法,注意向六个方向扩展时,要先判断是否越界,再判断是否可以入队:
- 遍历每个连通分量只取num大于阈值T的:
3,AC代码
4,解题过程
第一搏
实在没法理解题意(太菜了(;´༎ຶД༎ຶ`)),求助大神@日沉云起,终于弄明白了题意:三维BFS(由于DFS是递归进行,深度过大时,可能出现溢出,BFS则是利用队列,不会出现这种情况)
段错误。。。什么鬼
第二搏
判断条件一定要分清先后顺序。。。
第三搏
(我跟着大佬的代码,一步一步敲出来的,怎么会出错(╯‵□′)╯︵┻━┻。。。)
但,唯独漏了这一点
;虽然题目上说L是≤60的,也就是0-59,但还是取大一点为好。。。