题解:AT_abc184_c [ABC184C] Super Ryuma
Yizhi_Juruo · · 题解
AT_abc184_c [ABC184C] Super Ryuma题解
题目大意
有一个无限大的棋盘,问从
思路分析
显然答案不会超过
0 步
起点终点相同
1 步
满足三种条件之一。
2 步
- 曼哈顿距离
\leq 6 (可拆分为两步短距离移动,每步\leq 3 ); - 主对角线差值的绝对值
\leq 3 ,或副对角线差值的绝对值\leq 3 ; - 起点主对角线与终点副对角线的交点为整数坐标
((r_1-c_1+r_2+c_2) 为偶数) ,或起点副对角线与终点主对角线的交点为整数坐标((r_1+c_1+r_2-c_2) 为偶数) ;3 步不满足上述条件。
AC Code
#include<bits/stdc++.h>
#define int long long//1e9要开long long
using namespace std;
typedef pair<int, int>PII;
const int N = 3e5+10, mod = 998244353;
int r1, c1, r2, c2;
void solve() {
cin >> r1 >> c1 >> r2 >> c2;
int t1 = r1 - c1;
int t2 = r2 - c2;
int s1 = r1 + c1;
int s2 = r2 + c2;
int dx = abs(r1 - r2);
int dy = abs(c1 - c2);
int k = dx + dy;
int ans = 0;
if (r1 == r2 && c1 == c2) {
ans = 0;
} else if (s1 == s2 || t1 == t2 || k <= 3) {
ans = 1;
} else if (k <= 6 || abs(s1 - s2) <= 3 || abs(t1 - t2) <= 3 || (s1 + s2) % 2 == 0 || (t1 + s2) % 2 == 0) {
ans = 2;
} else {
ans = 3;
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}