- P105's solution
-
题解 P105
- @ 2026-2-10 22:02:01
问题描述
Sleeping Cup's Jump 是一种特殊的舞蹈动作,舞者需要使用尽量少的移动次数在二维舞台上从点 移动到 。每次移动可以选择一个实数 和一个角度 ,并从起始位置 移动到目标位置 。
数学性质分析
移动方式的数学表达
每次移动的位移向量为:
关键性质推导
将两式相除得:$\frac{d \times y}{d \times x} = \frac{\tan \phi}{\phi}$
由于 且 ,有以下性质:
- 符号相同: 和 同号,因此 和 必须同号
- 比值大于1:在 范围内,,因此 $\lvert d \times y \rvert > \lvert d \times x \rvert$
最小移动次数判断
0 次移动
当起点和终点相同时,不需要移动: 且
1 次移动
当位移满足以下条件时,可以通过一次移动到达:
- $\lvert d \times y \rvert > \lvert d \times x \rvert$
- 和 同号
2 次移动
其他所有情况都需要两次移动,包括:
- dx 或 dy 为 0
- $\lvert d \times y \rvert \le \lvert d \times x \rvert$
- 和 异号
AC code:
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("tangent.in", "r", stdin);
freopen("tangent.out", "w", stdout);
long long x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
long long dx = x2 - x1;
long long dy = y2 - y1;
if (dx == 0 && dy == 0) {
cout << 0 << endl;
} else if (dx != 0 && dy != 0 && (dx > 0 && dy > 0 || dx < 0 && dy < 0) && abs(dy) > abs(dx)) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
return 0;
}