求助(玄关)
查看原帖
求助(玄关)
866535
juruo5e59楼主2024/6/25 13:49

这道题我的错误很玄学(AC ×\times 48,WA ×\times 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;
}
2024/6/25 13:49
加载中...