搜索专题 BFS A1091.Acute Stroke(30)
Posted jasonpeng1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搜索专题 BFS A1091.Acute Stroke(30)相关的知识,希望对你有一定的参考价值。
#pragma warning(disable:4996) #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; struct node{ int x, y, z; }p; int m, n, l, t, volume = 0; int brain[1300][130][61], bbrain[1300][130][61]; //右,左,上,下,前,后 int X[] = { 0, 0, 0, 0, 1, -1 }; int Y[] = { 1, -1, 0, 0, 0, 0 }; int Z[] = { 0, 0, 1, -1, 0, 0 }; bool judge(int x, int y, int z){ if (x >= m || x < 0 || y >= n || y < 0 || z >= l || z < 0) return false; if (!brain[x][y][z] || bbrain[x][y][z]) return false; return true; } int BFS(int x, int y, int z){ int cnt = 0; queue<node> qn; p.x = x; p.y = y; p.z = z; qn.push(p); bbrain[x][y][z] = 1; while (!qn.empty()){ node top = qn.front(); qn.pop(); cnt++; for (int i = 0; i < 6; i++){ int nx = top.x + X[i], ny = top.y + Y[i], nz = top.z + Z[i]; if (judge(nx, ny, nz)){ p.x = nx; p.y = ny; p.z = nz; qn.push(p); bbrain[nx][ny][nz] = 1; } } } if (cnt >= t) return cnt; else return 0; } int main(){ scanf("%d %d %d %d", &m, &n, &l, &t); for (int k = 0; k < l; k++) for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) scanf("%d", &brain[i][j][k]); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) for (int k = 0; k < l; k++) if (brain[i][j][k] && bbrain[i][j][k] == 0) volume += BFS(i, j, k); printf("%d ", volume); system("pause"); return 0; }
参考:https://blog.csdn.net/ztmajor/article/details/81393476
以上是关于搜索专题 BFS A1091.Acute Stroke(30)的主要内容,如果未能解决你的问题,请参考以下文章
PAT 1091 Acute Stroke [难][bfs]
1091 Acute Stroke (30 分)难度: 一般 / bfs
PAT甲题题解-1091. Acute Stroke (30)-BFS