抓住那头奶牛
题目描述
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. 农夫约翰已经获悉逃跑的牛的位置,想立刻抓住它。
He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.
农夫约翰位于数轴上的点 N(0 ≤ N ≤ 100,000)处,奶牛位于同一数轴的点 K(0 ≤ K ≤ 100,000)处,他有两种移动方式:步行和闪移。
- Walking: FJ can move from any point
Xto the pointsX - 1orX + 1in a single minute 步行:每分钟可以从点X移动到X - 1或X + 1 - Teleporting: FJ can move from any point
Xto the point2 * Xin a single minute. 闪移:每分钟可以从点X移动到2 * X
If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it? 假设奶牛始终静止不动,请求出 Farmer John 抓住奶牛所需的最少时间(单位:分钟)。
输入描述
第一行:两个空格分隔的整数 N 和 K
输出描述
第一行:Farmer John 抓住奶牛所需的最少分钟数
输入样例
5 17
输出样例
4
提示
最快路径为 5 → 10 → 9 → 18 → 17,共耗时4分钟。
注意移动时下标防止越界,允许往回走。
本题为编程题,提交代码并运行通过测试点后判分。
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析