4 条题解
-
0
#include <bits/stdc++.h> using namespace std; const int N = 30 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long LLINF = 0x3f3f3f3f3f3f3f3fLL; char a[N][N][N]; struct Node{ int x, y, z, tim; }; int xx, yy, zz, sx, sy, sz, ex, ey, ez, dx[] = {1, -1, 0, 0, 0, 0}, dy[] = {0, 0, 1, -1, 0, 0}, dz[] = {0, 0, 0, 0, 1, -1}; bool flag; queue <Node> q; void bfs(int x, int y, int z){ a[x][y][z] = '#'; q.push((Node){x, y, z, 0}); while(!q.empty()){ Node t = q.front(); q.pop(); if(t.x == ex && t.y == ey && t.z == ez){ cout << "Escaped in " << t.tim << " minute(s).\n"; flag = true; return; } for(int i = 0 ; i < 6 ; i++){ int nx = t.x + dx[i], ny = t.y + dy[i], nz = t.z + dz[i]; if(nx >= 1 && nx <= xx && ny >= 1 && ny <= yy && nz >= 1 && nz <= zz && a[nx][ny][nz] != '#'){ q.push((Node){nx, ny, nz, t.tim + 1}); a[nx][ny][nz] = '#'; } } } } int main(){ while(cin >> xx >> yy >> zz){ if(xx == 0 && yy == 0 && zz == 0) return 0; for(int i = 1 ; i <= xx ; i++){ for(int j = 1 ; j <= yy ; j++){ for(int k = 1 ; k <= zz ; k++){ cin >> a[i][j][k]; if(a[i][j][k] == 'S'){ sx = i; sy = j; sz = k; } if(a[i][j][k] == 'E'){ ex = i; ey = j; ez = k; } } } } bfs(sx, sy, sz); if(!flag) cout << "Trapped!\n"; flag = false; } return 0; }
信息
- ID
- 1828
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 130
- 已通过
- 37
- 上传者