题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805375457411072

题意:

求三维的连通块

思路:

简单bfs

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<map>
 4 #include<set>
 5 #include<iostream>
 6 #include<cstring>
 7 #include<algorithm>
 8 #include<vector>
 9 #include<cmath>
10 #include<stack>
11 #include<queue>
12
13 #define inf 0x7fffffff
14 using namespace std;
15 typedef long long LL;
16 typedef pair<string, string> pr;
17
18 int m, n, l, t;
19 struct node{
20     int x, y, z;
21     node(){
22     }
23     node(int _x, int _y, int _z){
24         x = _x;
25         y = _y;
26         z = _z;
27     }
28 };
29
30 int dx[6] = {0, 0, 0, 0, 1, -1};
31 int dy[6] = {1, -1, 0, 0, 0, 0};
32 int dz[6] = {0, 0, 1, -1, 0, 0};
33 bool space[1300][130][65];
34 bool vis[1300][130][65];
35 int tot = 0;
36
37 bool check(int i, int j, int k)
38 {
39     if(i < 0 || i >= m || j < 0 || j >= n || k < 0 || k >= l)return false;
40     else return true;
41 }
42
43 void bfs(int x, int y, int z)
44 {
45     queue<node>que;
46     que.push(node(x, y, z));
47     vis[x][y][z] = true;
48     int cnt = 1;
49     while(!que.empty()){
50         node now = que.front();que.pop();
51         for(int i = 0; i < 6; i++){
52             int a = now.x + dx[i], b = now.y + dy[i], c = now.z + dz[i];
53             if(check(a, b, c) && !vis[a][b][c] && space[a][b][c]){
54                 que.push(node(a, b, c));
55                 vis[a][b][c] = true;
56                 cnt++;
57             }
58         }
59     }
60     if(cnt >= t){
61         tot += cnt;
62     }
63 }
64
65 int main()
66 {
67     scanf("%d%d%d%d", &m, &n, &l, &t);
68     for(int k = 0; k < l; k++){
69         for(int i = 0; i < m; i++){
70             for(int j = 0; j < n; j++){
71                 scanf("%d", &space[i][j][k]);
72             }
73         }
74     }
75
76
77     for(int k = 0; k < l; k++){
78         for(int i = 0; i < m; i++){
79             for(int j = 0; j < n; j++){
80                 if(!vis[i][j][k] && space[i][j][k])
81                     bfs(i, j, k);
82             }
83         }
84     }
85     printf("%d\n", tot);
86     return 0;
87 }

转载于:https://www.cnblogs.com/wyboooo/p/10658799.html

PAT甲级1091 Acute Stroke【三维bfs】相关推荐

  1. PAT甲级 1091 Acute Stroke(30) (Flood Fill)

    题目 One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the ...

  2. PAT甲级 1091 Acute Stroke

    使用DFS的话会报错,可能是递归的层数太多导致栈出问题了,使用BFS才可以AC //BFS 使用DFS的话会报错,可能是递归的层数太多导致栈出问题了,使用BFS才可以AC #include<io ...

  3. PAT甲题题解-1091. Acute Stroke (30)-BFS

    题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...

  4. 【PAT】1091 Acute Stroke (30 分)

    三维搜索,按照6个邻接理论,总会有重合的部分区域, 因此根据搜索顺序,先访问到的就是一个区域的[不能较真] #include <bits/stdc++.h> using namespace ...

  5. 1091. Acute Stroke (30)-PAT甲级真题(广度优先搜索)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  6. 1091 Acute Stroke (PAT甲级)

    这道题用dfs做的话,因为递归太多层,堆栈溢出,有两个测试点过不了:所以用bfs. 根据他人代码修改后的结果: #include <cstdio> #include <vector& ...

  7. 【PTA-A】1091 Acute Stroke (30 分)(BFS、队列)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  8. 1091. Acute Stroke (30)

    题目如下: One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given ...

  9. 1091 Acute Stroke (30)(30 分)

    One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...

  10. 【PAT甲级题解】1091 Acute Stroke (30分) BFS

    本题考BFS应用,题目大意是给出一个三维0,1矩阵,你需要对任意一个元素的上下左右前后进行判断枚举,如果当前元素为1且满足要求,则入队,当前枚举结束后如果该'1'矩阵不小于一个'l'代表的阈值则返回其 ...

最新文章

  1. android 中XML和对象转换利器Xstream的使用
  2. 成员函数的const究竟修饰的是谁
  3. Windows Server查看和记录远程登录信息的方法
  4. Linux上安装Bugfree系统
  5. 《编程珠玑(第2版•修订版)》—第2章2.5节原理
  6. Java线程池示例:任务窃取线程池WorkStealingPool
  7. innobackupex中--slave-info参数的含义和适用场景
  8. abap al设置单元格可编辑 oo_润乾报表美化设置 -- 样式
  9. Java 计算数学表达式(字符串解析求值工具)
  10. matlab迭代算法实例_智能优化算法及其MATLAB实例-免疫算法笔记
  11. Oracle建立用户和表空间
  12. 2018年机器学习算法工程师——秋招自我总结
  13. 产品读书《产品经理的第二本书》
  14. 谷歌浏览器发送POST请求(测试Post接口)
  15. simulink 汽车低压电网简单仿真
  16. sas字段有html脚本,sas 实现自动化报表格式之定性变量
  17. 学python多长时间、才能做点东西_如果只有1小时学Python,看这篇就够了
  18. 新浪微博登录html代码,新浪微博登录仿DiscuzX1.5论坛QQ登录样式 - YangJunwei
  19. 生成的包含卫兵:一次替代实用主义
  20. wordpress插件_您应该知道的2018年10个高级WordPress插件

热门文章

  1. python 栈_python:栈的理解与应用
  2. 【渝粤教育】国家开放大学2019年春季 0177-22T电机学(二) 参考试题
  3. SystemMenu添加Item
  4. 【CoRL 2018】通过元策略优化的MBRL算法
  5. (十四)三次样条插值
  6. 从Jensen不等式到Minkowski不等式
  7. docker-maven-plugin 推送镜像到 docker-hub
  8. STM32——项目需求之低功耗的停机模式
  9. DataGrid添加滚动条
  10. ubuntu14.04 配置jdk环境变量