汉诺塔
来源:互联网 发布:知乎回答能删除吗 编辑:程序博客网 时间:2024/06/14 20:26
#include<cstdio>int cnt=0;void hanoi(int n,char src,char tmp,char tag){if(n==1) printf("%d from %c to %c\n",n,src,tag);else {hanoi(n-1,src,tag,tmp);printf("%d from %c to %c\n",n,src,tag);hanoi(n-1,tmp,src,tag);}}void han(int n,char src,char tmp,char tag){if(n==1) cnt++;else{han(n-1,src,tag,tmp); cnt++;han(n-1,tmp,src,tag);}}int main(){int n;scanf("%d",&n);han(n,'A','B','C');printf("%d\n",cnt);hanoi(n,'A','B','C');return 0;}
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 汉诺塔
- 从头开始学习cocos2dx之笔记二(搭建ECLIPSE ANDROID JAVA环境)
- 学习GTD
- wiki1245-最小的N个和
- wiki3223素数密度
- 抄书问题
- 汉诺塔
- SCC之tarjan算法入门【HDU 1269】
- 001 ffmpeg
- Nmap速查表v1.0
- 动态规划之矩阵链乘法
- wustoj 1260 RMQ with Shifts 线段树单点更新
- CodeForces#203(Div.2)- A,B,C
- 写在回家之前
- 对“自学”的一些认识