hanoi(n,x,y,z)

{

hanoi(n-1,x,z,y);//n-1 from x to y

move(x,z);//x->z

hanoi(n-1,y,x,z);//n-1 from y to z

}

hanoi(n-1,x,z,y)

{

hanoi(n-2,x,y,z);//n-2 from x to z

move(x,y);//n-1 from x to y

hanoi(n-2,z,x,y);//n-2 from z to y

}

the step move(x,y)  is what  you must do to realize hanoi(n-2,x,y,z),at last ,the last step will meet the first step that you can implement easily,this is the deepest I can comprehend

//11072013 add

对hanoi T的印象从大二接触C语言开始

其实算法非常简单,当盘子的个数为n时,移动的次数应等于2^n – 1(有兴趣的可以自己证明试试看)。后来一位美国学者发现一种出人//摘自百度

#include <stdio.h>
#define N 2 //N disks on original pillar void hanoi(char src, char mid, char dst, int n)
{
if (n == 1)
{
printf("Move disk %d from %c to %c\n", n, src, dst);
}
else {
hanoi(src, dst, mid, n - 1);
printf("Move disk %d from %c to %c\n", n, src, dst);
hanoi(mid, src, dst, n - 1);
}
} int main(void)
{
hanoi('A', 'B', 'C', N);
return 0;
}

借鉴了其他人的思路,总算稍微理解了上述算法的实现,整理步骤要点

the fact is that wo don't konw how to do but konw wo must do,and push to opration to the stack memory until we move the topest disk  to Z

a)step befor moving n to Z,the case is 1 to n-1 are on Y,the mothed is move n to Z,push the opration//the last opration

b)the last second situation is 1 to n-2 are on X,the mothed is move n-1 to Z,push the opration//second last opration

d)it is ease to see the first step is move n-(n-1) to X or Y

a and b is what we must do,and we have no other choices,but what has hanppend bettwen b and c,the stack has store all the oprations wo must do until c

assume the function can move 1 to n-1 to X or Y, so it can move 1 to n-2 to X or Y,and so on n-(n-1) to X or Y,it is easy to move n-(n-1) to X or Y

the reverse order you or the functon you build may implement,

e)n-1 disks on Y,put n on Z//after that,you can omit n on Z

f)n-2 disks on X,n-1 on Y//put the n-1 on Z,the question return to a,so a and b is the whole task need to resolve

****the last situation is 2 disks on X or Y

the whole steps is like ,if 1 OK,then 2OK;if 2 OK,then 3 OK

个人感悟:1,有时候踢皮球也是一种办法,此处是往上踢,有点默认路由的味道,没有别的选择

     2,当你身处多级环境中,而且视野范围有限的情况下,只能虚构方法,即使不知道方法是怎么实现

3,the original case only permit taking one disk once,but it does't conflact with the step e and f,e and f is the situation we need implement but the mothed we use.The mothed is very simple,anyone can see directly,we image the situation first ,here the mothed is not the point

4,let the stack store the opration but not your head

5,用递归证明可以实现,用反证证明只有一种方式

Hanoi T note的更多相关文章

  1. Codeforces777E. Hanoi Factory 2017-05-04 18:10 42人阅读 评论(0) 收藏

    E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. Python学习札记(十四) Function4 递归函数 & Hanoi Tower

    reference:递归函数 Note 1.在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. eg.计算阶乘: #!/usr/bin/env python3 def ...

  3. codeforces-777E Hanoi Factory (栈+贪心)

    题目传送门 题目大意: 现在一共有N个零件,如果存在:bi>=bj&&bj>ai的两个零件i,j,那么此时我们就可以将零件j放在零件i上.我们现在要组成一个大零件,使得高度 ...

  4. poj 1920 Towers of Hanoi

    Towers of Hanoi Time Limit: 3000MS   Memory Limit: 16000K Total Submissions: 2213   Accepted: 986 Ca ...

  5. zoj 2954 Hanoi Tower

    Hanoi Tower Time Limit: 2 Seconds Memory Limit: 65536 KB You all must know the puzzle named "Th ...

  6. Codeforces 777E:Hanoi Factory(贪心)

    Of course you have heard the famous task about Hanoi Towers, but did you know that there is a specia ...

  7. 三星Note 7停产,原来是吃了流程的亏

    三星Note 7发售两个月即成为全球噩梦,从首炸到传言停产仅仅47天.所谓"屋漏偏逢连天雨",相比华为.小米等品牌对其全球市场的挤压.侵蚀,Galaxy Note 7爆炸事件这场连 ...

  8. 《Note --- Unreal --- MemPro (CONTINUE... ...)》

    Mem pro 是一个主要集成内存泄露检测的工具,其具有自身的源码和GUI,在GUI中利用"Launch" button进行加载自己待检测的application,目前支持的平台为 ...

  9. 《Note --- Unreal 4 --- Sample analyze --- StrategyGame(continue...)》

    ---------------------------------------------------------------------------------------------------- ...

随机推荐

  1. bash shell命令行选项与修传入参数处理

    在编写shell程序时经常需要处理命令行参数,本文描述在bash下的命令行处理方式.选项与参数:如下命令行: ./test.sh -f config.conf -v --prefix=/home -f ...

  2. 随机(Random)

    随机(Random)随机是智能的基础,人工智能的很多技术都需要用到随机,因此有必要把这个提到前面谈谈一考虑基于C/C++,般我们都是使用的rand ()等函数实现随机,当然我们也有吊炸天的boost库 ...

  3. JNDI学习总结(一)——JNDI数据源的配置

    一.数据源的由来 在Java开发中,使用JDBC操作数据库的四个步骤如下:   ①加载数据库驱动程序(Class.forName("数据库驱动类");) ②连接数据库(Connec ...

  4. linux下php-fpm 启动参数及重要配置

    约定几个目录 /usr/local/php/sbin/php-fpm/usr/local/php/etc/php-fpm.conf/usr/local/php/etc/php.iniI. php-fp ...

  5. .Net搭建的WebService测试页使用TextArea大文本框方便调试

    用.Net搭建的WebService,系统默认提供了测试页,供大家输入参数进行测试.但因为参数输入框使用的是单行input控件,导致无法输入换行文本,使得有些参数(如换行的xml)无法输入,及其不便. ...

  6. asr,tts,vsr

    http://max.book118.com/html/2014/0814/9432056.shtm   ASR技术的基础主要是信号处理和概率模型. 信号处理技术 语音信号处理 谱分析   基于时间的 ...

  7. Linux Socket过程详细解释(包括三次握手建立连接,四次握手断开连接)

    我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览器浏览网页时,浏览器的进程怎么与web 服务器通信的?当你用QQ聊天时,QQ进程怎么与服务器或你好友所在的QQ进程通信?这些都得靠s ...

  8. 安装PHPStudy2014,打开端口出现80端口 PID4 进程:System-windows服务器应用

    原文:安装PHPStudy2014,打开端口出现80端口 PID4 进程:System-windows服务器应用-黑吧安全网 安装PHPStudy2014,打开端口出现80端口 PID4 进程:Sys ...

  9. jquery在线手册

    开发时用到jquery,有几个函数想不起来怎么用,找了一下jquery在线手册. 记录一下,下回有需要再看看. 链接:http://www.chenfahui.cn/jq/

  10. http://localhost/certsrv 错误找不到页面解决方法

    http://localhost/certsrv 错误找不到页面解决方法 最近公司需要后台启动安全证书,可安装了“Active Directory证书服务” 后,http://localhost/ce ...