当前位置:网站首页>Catch That Cow (detailed)
Catch That Cow (detailed)
2022-07-30 04:42:00 【_rosy】
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) ona 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.
* Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute
* Teleporting: FJ can move from any point X to the point 2 × X in a single minute.
If the cow, unaware of its pursuit, does not move at all, how long does it take for Farmer John to retrieve it?
Input
Line 1: Two space-separated integers: N and K
Output
Line 1: The least amount of time, in minutes, it takes for Farmer John to catch the fugitive cow.
Sample
| Inputcopy | Outputcopy |
|---|---|
5 17 | 4 |
Hint
The fastest way for Farmer John to reach the fugitive cow is to move along the following path: 5-10-9-18-17, which takes 4 minutes.
When you first see this kind of question, you should think of breadth-first search, because here is to constantly test which one can reach the destination, and to judge the shortest number of steps. The shortest number of steps can be well judged through the queue.Because the queue is first-in, first-out, and in this question, each trial x-1, x+1, x*2 is an equal trial, and each time is the previous one plus 1, so the same when walkingThere is a situation where the number of steps has reached the end point, which is the shortest number of steps, because it is impossible for a y=x-1d to be equal to x+1 or x*2 at the same time, right, so when they are all threeUnder the same number of steps, there is a situation that comes first, that is the minimum number of steps
#include#include#include#include#include 边栏推荐
- MySQL String Concatenation - Various String Concatenation Practical Cases
- DAY17, CSRF vulnerability
- SSM框架简单介绍
- POJ1321 棋盘问题(详解)
- Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering
- DAY17:弱口令的探测与测试
- 共建共享数字世界的根:阿里云打造全面的云原生开源生态
- Code open source design and implementation ideas
- 【软件工程之美 - 专栏笔记】31 | 软件测试要为产品质量负责吗?
- BGP的简单实验
猜你喜欢

全流程调度——Azkaban入门与进阶

六、读取应用配置+日志配置

See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices

VUX Datetime 组件compute-days-function动态设置日期列表
Go study notes (84) - Go project directory structure

1. Get data - requests.get()

Thinkphp 5.0.24 Variable Override Vulnerability Causes RCE Analysis

WPF introduces ttf icon file usage record

The Azure developer news 丨 memorabilia in July

Android Studio 实现登录注册-源代码 (连接MySql数据库)
随机推荐
Weight line segment tree + line segment tree split/merge + CF1659D
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
山西省第二届网络安全技能大赛(企业组)部分赛题WP(七)
The Complete Go Books - Beginner to Advanced and Web Development
2.6归并排序
Usage of EFR32 as sniffer for Zigbee/Thread
swagger usage tutorial - quick use of swagger
【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
QT(39)-vs development qt program prompts that the source file cannot be opened
双指针问题(中)
Go study notes (84) - Go project directory structure
Detailed explanation of REUSE_ALV_GRID_DISPLAY
"Translation" Envoy Fundamentals, this is a training course, make people to more quickly using Envoy Proxy..
The VUX Datetime component compute-days-function dynamically sets the date list
山西省第二届网络安全技能大赛(企业组)部分赛题WP(十)
3. Dependency configuration management
Install MySQL Database on Kylin V10 Operating System
[C language] Program environment and preprocessing
How does MySql find out the latest data row that meets the conditions?
2021 Shandong Province Network Construction and Application Test Questions