标题:如何写出这个程序!!
只看楼主
wghost
Rank: 2
等 级:论坛游民
帖 子:47
专家分:31
注 册:2009-6-6
结帖率:37.5%
已结贴  问题点数:20 回复次数:4 
如何写出这个程序!!
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.

注意题目有多组输入
搜索更多相关主题的帖子: single 100 number minute points 
2010-04-11 10:14
james230932
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:162
专家分:629
注 册:2008-1-20
得分:4 
什么东东哦..先翻译好再发吧.

老天给了我十根纤纤玉指,我却用它们来挖鼻屎。
2010-04-11 14:12
cyhysr
Rank: 2
等 级:论坛游民
帖 子:8
专家分:17
注 册:2009-2-25
得分:4 
有点像ACM的试题。其实有点像比较两个不同的数的大小,并根据比较结果使一个数通过加减一或者乘二的方式使其等于另一个数.不过编程比较大小的时候要注意绝对值问题.
2010-04-11 19:04
wghost
Rank: 2
等 级:论坛游民
帖 子:47
专家分:31
注 册:2009-6-6
得分:0 
向三楼所说,不过要求步数最少!!
2010-04-12 06:23
herlev
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2010-4-11
得分:4 
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,影响编译吗?
2010-04-12 10:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-302506-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.315640 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved