周末游乐场:帮小源用C语言快速走出迷宫再玩火车水战!
```c #include <stdio.h> #define MAX_SIZE 100 int maze[MAX_SIZE][MAX_SIZE]; int visited[MAX_SIZE][MAX_SIZE]; int a, b; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; typedef struct { int x; int y; int step; } Node; Node queue[MAX_SIZE * MAX_SIZE]; int bfs(int xs, int ys, int xe, int ye) { int front = 0, rear = 0; queue[rear].x = xs; queue[rear].y = ys; queue[rear].step = 0; rear++; while (front < rear) { Node current = queue[front]; front++; if (current.x == xe && current.y == ye) { return current.step; } for (int i = 0; i < 4; i++) { int nx = current.x + dx[i]; int ny = current.y + dy[i]; if (nx >= 0 && nx < a && ny >= 0 && ny < b && maze[nx][ny] == 0 && !visited[nx][ny]) { visited[nx][ny] = 1; queue[rear].x = nx; queue[rear].y = ny; queue[rear].step = current.step + 1; rear++; } } } return -1; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int c, xs, ys, xe, ye; scanf("%d %d %d", &a, &b, &c); for (int j = 0; j < a; j++) { for (int k = 0; k < b; k++) { maze[j][k] = 0; visited[j][k] = 0; } } for (int j = 0; j < c; j++) { int x, y; scanf("%d %d", &x, &y); maze[x][y] = 1; } scanf("%d %d %d %d", &xs, &ys, &xe, &ye); int result = bfs(xs, ys, xe, ye); if (result == -1) { printf("not arrive\n"); } else { printf("%d\n", result); } } return 0; } ``` ######[AI写代码神器 | 1249点数解答 | 2024-11-24 18:45:30]
- 迷宫探秘:求解扶苏走出数字矩阵迷宫所需步数及循环判定(字节豆包 | 819点数解答 | 2025-11-26 19:27:35)87
- Python实现打车费用计算:避开分段计价与等候计费陷阱!(字节豆包 | 300点数解答 | 2025-10-31 09:40:28)126
- C++ 实现打车费用计算:这些开发要点你注意了吗?(字节豆包 | 505点数解答 | 2025-10-31 10:03:34)115
- 周末打车去游乐园:费用计算代码揭秘及注意要点(字节豆包 | 346点数解答 | 2026-02-10 15:28:01)51
- 出租车车费计算的 Python 实现及开发要点(字节豆包 | 987点数解答 | 2026-02-15 14:45:59)49
- C++实现打车费用计算及开发建议(字节豆包 | 656点数解答 | 2026-02-15 14:47:59)51
- C++打车计费程序实现与开发要点详解(DeepSeek | 1377点数解答 | 2026-02-15 14:50:49)43
- 超详细:实现LED灯中速→慢速→快速循环闪烁及特定顺序闪烁的程序修改方案(字节豆包 | 865点数解答 | 2024-10-20 21:13:53)258
- DSP2833x:实现D14、D12、D10 LED按中速→慢速→快速顺序循环闪烁的代码优化(阿里通义 | 1309点数解答 | 2024-10-20 21:14:18)264
- 修改 DSP2833x 程序:实现 LED 灯中速→慢速→快速闪烁及特定顺序循环闪烁 (GPT | 1312点数解答 | 2024-10-20 21:14:21)283
- 3ds max 数字化制图技术:破解项目设计难题的利器(字节豆包 | 198点数解答 | 2024-11-05 21:33:01)214
- 3ds Max技术助力项目设计难题化解(阿里通义 | 244点数解答 | 2024-11-05 21:33:59)221