c++ - Semi tower of hanoi
问题描述
void semiHanoi(int n, char source, char destination, char temp) {
if (n == 2) {//base case
cout << "Move from " << source << " to " << destination << endl;
cout << "Move from " << temp << " to " << destination << endl;
}
else {
semiHanoi((n - 1), source, destination, temp);//to make moves
semiHanoi(2, destination, temp, source);
//semiHanoi(2 * (n - 1), destination, source, temp);
}
}
I am tried a lot but could not figure out what and how the recursive calls should go! Please Help
This is the question: Semi-Hanoi is a problem very similar to Hanoi problem. The only difference is that your input in semi-Hanoi must be an even number of disks like 2n and they are set as shown in the following figure-a. The peg A has all the even numbered disks such as 2,4,6, … and the peg B has the rest (all the odd numbered disks such as 1,3,5,...). the rules of movement in semi-Hanoi is the same as Hanoi’s rules: • only one disk can be moved at a time • a bigger disk cannot be placed on top of a smaller one The goal is to move all the disks on the peg C in order as shown in figure-b here is the image how disks initially looks like
解决方案
推荐阅读
- sql-server - 有没有办法在 t-sql 脚本中切换服务器上下文?
- python - 我必须转换列才能在 sqlite3 中正确使用它们的问题
- ruby-on-rails - 在创建评论时,无缘无故地获得“多次调用渲染和/或重定向”
- python - 如何使用random.choice 和alternation 循环?
- javascript - 插入 json 对象数组
- javascript - 在 javascript Rock, Paper, Scissors Game 中记分有问题
- python - 如何通过 pyserial 与 24 字节的 Vacom VAX 控制器通信?
- python - python中的扑克手评估:为什么naive比bit hash快?
- apache-spark - spark 1.6 任务永无止境
- file - 将文件显示为 docker windows 容器的日志