注册 登录
编程论坛 C++教室

如何写出这个程序!!

wghost 发布于 2010-04-11 10:14, 928 次点击
Description

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.

* 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 Input

5 17

Sample Output

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.

注意题目有多组输入
4 回复
#2
james2309322010-04-11 14:12
什么东东哦..先翻译好再发吧.
#3
cyhysr2010-04-11 19:04
有点像ACM的试题。其实有点像比较两个不同的数的大小,并根据比较结果使一个数通过加减一或者乘二的方式使其等于另一个数.不过编程比较大小的时候要注意绝对值问题.
#4
wghost2010-04-12 06:23
向三楼所说,不过要求步数最少!!
#5
herlev2010-04-12 10:36
Description

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?
牛不知道被追,所以根本不动。那么约翰大约多久能找到牛?
Input
输入:
Line 1: Two space-separated integers: N and K
两个整数N 和K
Output
输出

Line 1: The least amount of time, in minutes, it takes for Farmer John to catch the fugitive cow.
第一行:约翰最短可以在多少分钟内把牛找到。
Sample Input
例如:输入
5 17
输出
Sample Output

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.
约翰找到逃跑的牛最短的路径是:5-10-9-18-17,这需要4分钟时间。

我帮楼主翻译了,大家做题。

也请各位帮我一个忙,告诉我一个VC6.0的下载链接,要试过没问题的。另外请问,安装VC6.0是否同时要安装MSDN,影响编译吗?
1