#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
int dir[8][2] = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, 2}, {1, -2}, {2, 1}, {2, -1}};
int map[15][15], sx, sy, tar_x, tar_y;
bool vis[15][15];
struct node {
int x;
int y;
};
bool inmap(int x, int y) {
return x >= 1 && x <= 8 && y >= 1 && y <= 8;
}
void bfs(int x, int y) {
vis[x][y] = 1;
queue<node> q;
q.push({x, y});
map[x][y] = 0;
while (!q.empty()) {
node now = q.front();
for (int i = 0; i < 8; i++) {
int nx = now.x + dir[i][0];
int ny = now.y + dir[i][1];
if (inmap(nx, ny) && !vis[nx][ny]) {
vis[nx][ny] = 1;
map[nx][ny] = map[now.x][now.y] + 1;
q.push({nx, ny});
}
}
q.pop();
}
}
int main() {
cin >> sx >> sy >> tar_x >> tar_y;
bfs(sx, sy);
cout << map[tar_x][tar_y];
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】