At_abc359求助
  • 板块学术版
  • 楼主juruo5e59
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/6/24 11:29
  • 上次更新2024/6/24 16:19:20
查看原帖
At_abc359求助
866535
juruo5e59楼主2024/6/24 11:29

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;
}
2024/6/24 11:29
加载中...