这道题我的错误很玄学(AC × 48,WA × 1)奆佬们帮我看看
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dis(int u, int v) {return abs(u - v);}
int disx(int x1, int y1, int x2, int y2) {
int d = dis(x1, x2) - dis(y1, y2);
if (x1 > x2) {
if ((x2 % 2 == 1 && y1 % 2 == 0) || (x2 % 2 == 0 && y1 % 2 == 1))
d ++;
}
else {
if ((x1 % 2 == 1 && y1 % 2 == 0) || (x1 % 2 == 0 && y1 % 2 == 1))
d ++;
}
return d / 2;
}
bool check(int x1, int y1, int x2, int y2) {
int s = 0;
if (x1 > x2) {
s = x1 - dis(y1, y2);
if ((x1 % 2 == 1 && y1 % 2 == 0) || (x1 % 2 == 0 && y1 % 2 == 1))
s --;
return x2 >= s;
}
else {
s = x1 + dis(y1, y2);
if ((x1 % 2 == 0 && y1 % 2 == 0) || (x1 % 2 == 1 && y1 % 2 == 1))
s ++;
return x2 <= s;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (check(x1, y1, x2, y2))
cout << dis(y1, y2) << endl;
else cout << disx(x1, y1, x2, y2) + dis(y1, y2) << endl;
return 0;
}