查看: 2046| 回复: 10
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/4-3/10 CareerCup 3.4

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (i.e., each disk sits on top of an even larger one). You have the following constraints:
(1) Only one disk can be moved at a time.
(2) A disk is slid off the top of one tower onto the next tower.
(3) A disk can only be placed on top of a larger disk.
Write a program to move the disks from the first tower to the last using stacks.

发帖规范:
http://www.1point3acres.com/bbs/thread-48094-1-1.html
http://www.1point3acres.com/bbs/thread-32423-1-1.html

上一篇:[第二轮] 3/4-3/10 CareerCup 3.3
下一篇:[第二轮] 3/4-3/10 CareerCup 3.5
🔗
EchoMemory 2013-3-3 21:31:32 | 只看该作者
全局:
本帖最后由 EchoMemory 于 2013-3-3 21:33 编辑

I don't know what the connection between the problem and the Stack is...Anyway, it is a classic problem. Using recursion could solve that.
回复

使用道具 举报

🔗
ryancooper 2013-3-4 09:32:08 | 只看该作者
全局:
EchoMemory 发表于 2013-3-3 21:31
I don't know what the connection between the problem and the Stack is...Anyway, it is a classic prob ...

Since all recursive algorithm implicitly uses stack, I think what they are asking is to convert the original recursive algorithm into an iterative algorithm that explicitly uses stack
回复

使用道具 举报

🔗
EchoMemory 2013-3-4 12:21:23 | 只看该作者
全局:
ryancooper 发表于 2013-3-4 09:32
Since all recursive algorithm implicitly uses stack, I think what they are asking is to convert th ...

I see,thx:)
回复

使用道具 举报

🔗
cjsp 2013-3-8 19:40:11 | 只看该作者
全局:
EchoMemory 发表于 2013-3-3 21:31
I don't know what the connection between the problem and the Stack is...Anyway, it is a classic prob ...

Maybe they just want you to use stacks to simulate towers...
回复

使用道具 举报

🔗
cjsp 2013-3-8 19:45:33 | 只看该作者
全局:
EchoMemory 发表于 2013-3-3 21:31
I don't know what the connection between the problem and the Stack is...Anyway, it is a classic prob ...

看了一下答案 还真是。。。晕
回复

使用道具 举报

🔗
ThunderXu 2013-3-9 20:32:02 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5124029
use recursion, if I wish to move all n disks from 1 to 3, I should move all n-1 disks from 1 to 2 first to let the nth disk to be move from 1 to 3, and to move all n-1 disks from 1 to 2 I should...
回复

使用道具 举报

🔗
Fanyare 2013-3-13 05:49:02 | 只看该作者
回复

使用道具 举报

🔗
grassgigi 2013-3-14 13:52:08 | 只看该作者
全局:
递归,用stack表示tower
https://gist.github.com/chrislukkk/5159124
回复

使用道具 举报

全局:
f(n) = 2 f(n-1) + 1
*  f(N) = O(2^N)
*  
*  useful link : http://blog.csdn.net/xujinsmile/article/details/8091738
*  此人代码写的有点混乱。。。。
*  自己果然只是中人之资  智力硬伤。。。
*  对递归的认识还不够。。。别人写的代码能看懂,自己想就跪了。。。。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表