// 2023 IUSB Programming Competition // Round 1 Problem 4 // Knight Movement // Solution by Liguo Yu #include using namespace std; bool oneStep(int x1, int y1, int x2, int y2); int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int steps; if(x1==x2 && y1==y2) steps = 0; else if (oneStep(x1, y1, x2, y2)) steps = 1; else if (oneStep(x1, y1, x2+1, y2+2)) steps = 2; else if (oneStep(x1, y1, x2+1, y2-2)) steps = 2; else if (oneStep(x1, y1, x2-1, y2+2)) steps = 2; else if (oneStep(x1, y1, x2-1, y2-2)) steps = 2; else if (oneStep(x1, y1, x2+2, y2+1)) steps = 2; else if (oneStep(x1, y1, x2+2, y2-1)) steps = 2; else if (oneStep(x1, y1, x2-2, y2+1)) steps = 2; else if (oneStep(x1, y1, x2-2, y2-1)) steps = 2; else steps = -1; if(steps != -1) cout << steps << endl; else cout << ">2" << endl; return 0; } bool oneStep(int x1, int y1, int x2, int y2) { if((x2 == x1+1 && y2 == y1+2) || (x2 == x1+2 && y2 == y1+1) || (x2 == x1+1 && y2 == y1-2) || (x2 == x1+2 && y2 == y1-1) || (x2 == x1-1 && y2 == y1-2) || (x2 == x1-2 && y2 == y1-1) || (x2 == x1-1 && y2 == y1+2) || (x2 == x1-2 && y2 == y1+1)) return true; else return false; }