抓住那头牛:
农夫知道一头牛的位置,想要抓住它。农夫和牛都位于数轴上,农夫起始位于点N(0<=N<=100000),牛位于点K(0<=K<=100000)。农夫有两种移动方式:
1、从X移动到X-1或X+1,每次移动花费一分钟
2、从X移动到2*X,每次移动花费一分钟
假设牛没有意识到农夫的行动,站在原地不动。农夫最少要花多少时间才能抓住牛?
Catch that cow:
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN (0 ≤N ≤ 100,000) on a number line and the cow is at a pointK (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting.

本文介绍了如何使用C++编程解决'抓住那头牛'问题。农夫从点N出发,牛位于点K,农夫有两种移动方式,通过广度优先搜索策略寻找抓住牛的最短时间。问题要求找到农夫在不移动牛的情况下,用最少的时间捕捉到牛。

被折叠的 条评论
为什么被折叠?



