样例都没过······

P1747 好奇怪的游戏

艹打错了```x_2,y_2```
by ajahjahah @ 2022-07-26 11:01:19


改了之后样例就对了 ```cpp #include <iostream> #include <queue> #include <cmath> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int dx[] = { 1,1,2,2,2,2,-1,-1,-2,-2,-2,-2 }; int dy[] = { -2,2,-2,-1,1,2,-2,2,-1,1,-2,2 }; int x_1, y_1, x_2, y_2; bool vis[25][25]; struct Firefox { int x, y, step; }; int bfs(int sx, int sy) { queue<Firefox> q; memset(vis, 0, sizeof(vis)); Firefox cur = { sx , sy , 0 }; vis[sx][sy] = true; q.push(cur); while (!q.empty()) { cur = q.front(); q.pop(); if (cur.x == 1 && cur.y == 1) return cur.step; for (int i = 0; i <= 11; i++) { int nx = cur.x + dx[i]; int ny = cur.y + dy[i]; if (nx >= 1 && nx <= 25 && ny >= 1 && ny <= 25 && !vis[nx][ny]) { Firefox nxt = { nx , ny , cur.step + 1 }; vis[nx][ny] = true; q.push(nxt); } } } return -1; } int main() { cin >> x_1 >> y_1 >> x_2 >> y_2; cout << bfs(x_1, y_1) << endl; cout << bfs(x_2, y_2) << endl;//这里 return 0; } ```
by ajahjahah @ 2022-07-26 11:02:36


@[WACE_QWQ](/user/602555) 两个bfs(x1,y1)
by tin_ingot @ 2022-07-26 11:10:45


鲁达能
by retep @ 2022-07-26 11:18:29


鲁大能
by henrywyh @ 2022-07-26 11:18:56


|