logo AlgoBeat OnlineJudge
登录 注册

Official Editorial

作者: 035966_L3  ·  发布于 2026-06-14 20:43:42  ·  最后修改于 2026-06-14 20:54:32
已通过
审核员:joe_zxq 彩笔 · 2026-06-14 20:54:32

https://scg3.piaoztsdy.cn/p/105

显然 。考虑一次移动中轨迹的斜率 。画图可知,当 时,

也就是说,如果直线 的斜率 且存在,那么就可以从 一次性移动到

很明显,如果我们第一次移动时选择 ,那么一次移动后的位置 与终点 之间的斜率将会极其接近 ,显然可以从 一次性移动到 。整个过程一共移动了 次,所以答案总是不超过

综上,本题的结论是(设 为起点, 为终点):

  • 重合时答案为
  • 且存在时答案为
  • 以上两个条件都不满足时答案为
#include <bits/stdc++.h>
using namespace std;
#define y1 Y1

int steps(int x1, int y1, int x2, int y2)
{
	if (x1 == x2 && y1 == y2) return 0;
	if (x2 > x1 && y2 - y1 > x2 - x1) return 1;
	if (x1 > x2 && y1 - y2 > x1 - x2) return 1;
	return 2;
}
int main()
{
	freopen("tangent.in", "r", stdin);
	freopen("tangent.out", "w", stdout);
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << steps(x1, y1, x2, y2) << endl;
	return 0;
}

暂无评论

登录 后即可评论。