抓住那头奶牛

ch850405 程序题 共 个子题

题目描述

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 X to the points X - 1 or X + 1 in a single minute 步行:每分钟可以从点 X 移动到 X - 1 或 X + 1
  • Teleporting: FJ can move from any point X to the point 2 * X in 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分钟。 注意移动时下标防止越界,允许往回走。

本题为编程题,提交代码并运行通过测试点后判分。

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
提交记录
共 条 仅展示自由练习提交
正在加载提交记录…
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧