1 条题解
-
0
#include <iostream> #include <queue> #include <cstring> using namespace std; struct Point { int x, y, z; } S, E; queue<Point> q; int dx[] = {1, -1, 0, 0, 0, 0}; int dy[] = {0, 0, 1, -1, 0, 0}; int dz[] = {0, 0, 0, 0, 1, -1}; char g[35][35][35]; bool vis[35][35][35]; int dis[35][35][35]; int l, r, c; bool check(Point x) { return g[x.x][x.y][x.z] != '#' && !vis[x.x][x.y][x.z]; } int main() { while (cin >> l >> r >> c && l && r && c) { memset(g, '#', sizeof(g)); for (int i = 1; i <= l; i++) for (int j = 1; j <= r; j++) for (int k = 1; k <= c; k++) { cin >> g[i][j][k]; vis[i][j][k] = false; if (g[i][j][k] == 'S') { S = (Point){i, j, k}; vis[i][j][k] = true; dis[i][j][k] = 0; q.push(S); } if (g[i][j][k] == 'E') E = (Point){i, j, k}; } while (!q.empty() && !vis[E.x][E.y][E.z]) { Point h = q.front(); q.pop(); for (int i = 0; i < 6; i++) { Point now = (Point){h.x + dx[i], h.y + dy[i], h.z + dz[i]}; if (check(now)) { vis[now.x][now.y][now.z] = true; dis[now.x][now.y][now.z] = dis[h.x][h.y][h.z] + 1; q.push(now); } } } while (!q.empty()) q.pop(); if (!vis[E.x][E.y][E.z]) cout << "Trapped!\n"; else cout << "Escaped in " << dis[E.x][E.y][E.z] << " minute(s).\n"; } return 0; }
- 1
信息
- ID
- 467
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 83
- 已通过
- 32
- 上传者