社区讨论
样例都没过······
P1747好奇怪的游戏参与者 5已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lo8gsbcd
- 此快照首次捕获于
- 2023/10/27 18:22 2 年前
- 此快照最后确认于
- 2023/10/27 18:22 2 年前
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_1, y_1) << endl;
return 0;
}
有没有dalao康康哪里不对啊
回复
共 5 条回复,欢迎继续交流。
正在加载回复...