#include<bits/stdc++.h>
using namespace std;
int hx, hy, vis[25][25], ans = 1e9, dx[20] = {1, 1, 2, 2, 2, 2, -1, -1, -2, -2, -2, -2}, dy[20] = {-2, 2, -2, -1, 1, 2, -2, 2, -1, 1, -2, 2};
struct node{
int x, y, step;
node(int ax = 0, int ay = 0, int astep = 0) {
x = ax, y = ay, step = astep;
}
};
void bfs(int x, int y, int step) {
queue<node> q;
q.push(node(x, y, step));
while(!q.empty()) {
node fro = q.front();
q.pop();
int nx = fro.x, ny = fro.y, nstep = fro.step;
if(nx == 1 && ny == 1) {
ans = min(nstep, ans);
//cout << endl << endl;
continue;
}
if(nx < 1 || ny < 1 || nx > 20 || ny > 20) continue;
if(vis[nx][ny]) continue;
vis[nx][ny] = 1;
//cout << nx << " " << ny << endl;
for (int i = 0; i < 12; i++) {
q.push(node(nx + dx[i], ny + dy[i], nstep + 1));
}
}
}
int main(void) {
cin >> hx >> hy;
//vis[hx][hy] = 1;
bfs(hx, hy, 0);
cout << ans << endl;
ans = 1e9;
memset(vis, 0, sizeof(vis));
//vis[hx][hy] = 1;
cin >> hx >> hy;
bfs(hx, hy, 0);
cout << ans;
return 0;
}
手输和复制两种都能正常返回值, 求dalao解答。