```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; } ``` [2024-11-24 18:45:30 | AI写代码神器 | 1249点数解答]