AtCoder Beginner Contest 184

比赛链接

C Super Ryuma

Description

题目链接

Solution

观察可得最多移动三次即可从起点到终点。
分情况讨论:

  • 起点和终点重合,总步数为 0
  • 共对角线或者曼哈顿距离不超过 3,总步数为 1
  • 走两次对角线,即与起点曼哈顿距离为偶数,总步数为 2
  • 起点的近邻点,即与起点曼哈顿距离不超过 6,总步数为 2
  • 与对角线的距离曼哈顿距离不超过 3,总步数为 2
  • 其它情况,总步数为 3

Code

Super Ryuma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
#define int long long

using namespace std;

int a, b, c, d;

signed main() {
cin >> a >> b >> c >> d;
if (a == c && b == d) cout << 0 << endl;
else if (a + b == c + d || a - b == c - d || (abs(a - c) + abs(b - d) <= 3)) {
cout << 1 << endl;
} else if ((abs(a - c) + abs(b - d)) & 1){
if (abs(a + b - c - d) <= 3) cout << 2 << endl;
else if (abs(a - b - c + d) <= 3) cout << 2 << endl;
else if (abs(a - c) + abs(b - d) <= 6) cout << 2 << endl;
else cout << 3 << endl;
} else cout << 2 << endl;
return 0;
}

D increment of coins

Description

题目链接

Solution

解法一:动态规划逆推
问题相当于

Code

increment of coins
1
2


E Valid payments

Description

题目链接

Solution

Code

Valid payments
1
2


F Valid payments

Description

题目链接

Solution

Code

Valid payments
1
2