博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(算法)Hanoi Problem汉诺塔问题
阅读量:4624 次
发布时间:2019-06-09

本文共 925 字,大约阅读时间需要 3 分钟。

Problem:

There are three poles and N disks where each disk is heaver than the next disk. In the initial conguration, the discs are stacked upon another on the first pole where the lighter discs are above the heavier discs. We want to move all the discs to the last pole with the following conditions:

  • Only one disc can be moved from one pole to another at a time.
  • The discs have to be stacked such that all the lighter discs are on top of the heavier ones.

Recursion:

To move N discs from the first pole to the last pole, we need to move N-1 discs to the middle pole, then move the Nth disc to the last pole, and then move all N-1 discs from the middle pole back to the last pole.

Code: 

#include 
using namespace std;void hanoi(int N,int start,int helper,int destination){ if(N==1) cout<<"Move "<
<<" to "<
<

转载于:https://www.cnblogs.com/AndyJee/p/4692447.html

你可能感兴趣的文章
网络编程基础之socket编程
查看>>
各种浏览器的user-agent和
查看>>
Restful levels
查看>>
Phonegap移动开发:布局总结(一) 全局
查看>>
Java 变参函数的实现
查看>>
nrf51 SDK自带例程的解读
查看>>
SESSION技术
查看>>
数据结构(五)之直接插入排序
查看>>
SQL函数——LENGTH()和LENGTHB()
查看>>
vim - manual -个人笔记
查看>>
详解Javascript中prototype属性(推荐)
查看>>
angularjs实现首页轮播图
查看>>
Git 对象 和checkout 和stash的笔记
查看>>
团队项目总结2-服务器通信模型和顺序图
查看>>
hdu 1085 Holding Bin-Laden Captive!
查看>>
[周记]8.7~8.16
查看>>
递归定义
查看>>
kindeditor 代码高亮设置
查看>>
图的邻接表存储
查看>>
2018 leetcode
查看>>