| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4727 人关注过本帖
标题:在一堵无限长的墙上找门的问题,求最有效率的算法
取消只看楼主 加入收藏
lrmymycn
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-8-23
收藏
 问题点数:0 回复次数:4 
在一堵无限长的墙上找门的问题,求最有效率的算法

你面对着一堵墙,左右2边都无限长

墙上有一扇门,有可能在左边也有可能在右边,你只有站在门前才能看到这扇门

求找这扇门最有效率的算法 O(n),门离你初始位置有n步

我的做法是 0 1 -1 2 -2 3 -3 。。这样一直找下去

不知道对不对,请教


付上原题,希望没有理解错误

You are facing a wall that stretches infinitely in both directions. There is a door in the wall, but you know neither how far away nor in which direction. You can see the door only when you are right next to it. Design an algorithm that enables you to reach the door by walking at most O(n) steps where n is the (unknown to you) number of steps between your initial position and the door.

搜索更多相关主题的帖子: 有效率 算法 
2006-08-25 15:37
lrmymycn
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-8-23
收藏
得分:0 

楼上的有什么好的建议吗?

2006-08-27 01:13
lrmymycn
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-8-23
收藏
得分:0 

OK。多谢回答

2006-08-27 21:15
lrmymycn
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-8-23
收藏
得分:0 
Design an algorithm that enables you to reach the door by walking at most O(n) steps where n is the (unknown to you) number of steps between your initial position and the door.

这里是说steps,但是好像做路程的话题目会比较有趣

我去问问老师先

感谢大家帮忙
2006-08-30 02:06
lrmymycn
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-8-23
收藏
得分:0 

刚问了,这里的steps是只脚步,不是指步骤,和楼上说的一样

2006-08-30 13:52
快速回复:在一堵无限长的墙上找门的问题,求最有效率的算法
数据加载中...
 
   



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

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