rt,这个比赛的C题我的代码出现了很玄学的问题,WA了一个点AC48个点(不知道是不是管理员开摆了,题库里好像没有)
#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;
}