3 条题解
-
0
罗梓豪LZH (xxw58) LV 9 @ 2024-1SB
#include <iostream> #include <queue> #include <vector> #include <tuple> using namespace std; struct Point { int l, r, c; }; int main() { while (true) { int L, R, C; cin >> L >> R >> C; if (L == 0 && R == 0 && C == 0) break; vector<vector<vector<char>>> maze(L, vector<vector<char>>(R, vector<char>(C))); queue<tuple<int, int, int, int>> q; // (l, r, c, time) Point start, end; for (int l = 0; l < L; ++l) { for (int r = 0; r < R; ++r) { for (int c = 0; c < C; ++c) { cin >> maze[l][r][c]; if (maze[l][r][c] == 'S') { start = {l, r, c}; } else if (maze[l][r][c] == 'E') { end = {l, r, c}; } } } } q.push({start.l, start.r, start.c, 0}); vector<vector<vector<bool>>> visited(L, vector<vector<bool>>(R, vector<bool>(C, false))); visited[start.l][start.r][start.c] = true; int dl[] = {-1, 1, 0, 0, 0, 0}; int dr[] = {0, 0, -1, 1, 0, 0}; int dc[] = {0, 0, 0, 0, -1, 1}; bool found = false; int escape_time = -1; while (!q.empty()) { auto [l, r, c, t] = q.front(); q.pop(); if (l == end.l && r == end.r && c == end.c) { found = true; escape_time = t; break; } for (int i = 0; i < 6; ++i) { int nl = l + dl[i]; int nr = r + dr[i]; int nc = c + dc[i]; if (nl >= 0 && nl < L && nr >= 0 && nr < R && nc >= 0 && nc < C && !visited[nl][nr][nc] && maze[nl][nr][nc] != '#') { visited[nl][nr][nc] = true; q.push({nl, nr, nc, t + 1}); } } } if (found) { cout << "Escaped in " << escape_time << " minute(s)." << endl; } else { cout << "Trapped!" << endl; } } return 0; }
-
0
题解在下面: 1 2 3 4 5 6 7 8 9 0 1 1 1 11 1 1 1 1 11 1 1 11 1 1 11 1 1 11 1 1 11 1 1 1 11 1 1 11 1 11 1 1 11 1 11 1 1 11 1 1 11 1 1 11 1 11 1 11 1 1 11 1 1 11 1 11 1 1 1 1 1 11 1 本题思路如下: 1 1 11 1 1 11 1 1 1 11 1 1 1 1 11 1 1 1 1 1 1 111 1 1 1 1 1 1 1 1 1 算了直接给答案吧: 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1
1 1 1
1 1 1 1 1 1 1 1 1 1 11 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 11
1 1 1 快了!1 1 1 1 1 1 11
11
1 1 1 11 1 1 1
1
1 1 1 11
1 1 加油1 1 1 1 1
1 1 1 11 1
1 1 1 1 1
1 1 1 1 你要做个乖孩纸! 这里没题解! 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1
1 1
- 1
信息
- ID
- 728
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 1
- 已通过
- 1
- 上传者