当前位置:网站首页>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 边栏推荐
- Simulation problem (middle)
- 【MySQL系列】-B+树索引和HASH索引有什么区别
- Shi Xingguo, founder of Hyperchain, was interviewed by 21st Century Business Herald to interpret Shanghai's new NFT regulations and digital development
- KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
- Shanxi group (enterprises) in the second network security skills competition part problem WP (8)
- The Complete Go Books - Beginner to Advanced and Web Development
- Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds
- 文件系统二
- 解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
- 2.5快速排序
猜你喜欢

MYSQL unique constraint

MySQL operation statement Daquan (detailed)

2.4 hill sorting

Database Design of Commodity Management System--SQL Server

05全局配置文件application.properties详解

【Redis高手修炼之路】Jedis——Jedis的基本使用

DAY17: weak password detection and test
![[Awards every week] The](/img/78/4b510b190475d603490614d2c8199f.png)
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
![[C language] Program environment and preprocessing](/img/d2/a0437da7d651e755951dd2a15827cf.png)
[C language] Program environment and preprocessing

Shanxi group (enterprises) in the second network security skills competition part problem WP (7)
随机推荐
1. Get data - requests.get()
Install MySQL Database on Kylin V10 Operating System
A brief introduction to the SSM framework
Unity beginner 5 cameras follow, border control and simple particle control (2 d)
【软件工程之美 - 专栏笔记】31 | 软件测试要为产品质量负责吗?
Double pointer problem (middle)
The VUX Datetime component compute-days-function dynamically sets the date list
精品MySQL面试题,备战八月99%必问!过不了面试算我的
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
数据库概论 - MySQL的简单介绍
山西省第二届网络安全技能大赛(企业组)部分赛题WP(七)
How does MySql find out the latest data row that meets the conditions?
Simple experiment with BGP
聊一聊什么是SaaS,以及遇到的问题......
《构建之法》笔记---第十章 典型用户和场景
Weight line segment tree + line segment tree split/merge + CF1659D
2.6 Merge Sort
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
handler+message [message mechanism]
@WebServlet注解(Servlet注解)