|
1楼 我不太清楚怎样编写和怎样实现动画效果 希望大家多多帮忙 |
|
|
|
- 共有26篇贴子
| 61.131.58.* |
2楼 |
|
|
|
3楼 |
|
|
|
| 221.12.124.* |
6楼 |
|
|
| 60.5.35.* |
8楼 |
|
|
| 219.243.0.* |
9楼 |
|
|
|
12楼 # include < iostream.h > void hanoi ( int n, char a, char b, char c ) { if ( n >= 1 ) { hanoi ( n-1, a, c, b ) ; cout << a << " --> " << c << endl ; hanoi ( n-1, b, a, c ) ; } } void main () { int m ; cout << " Input the number of diskes: " << endl ; cin >> m ; hanoi ( m, 'A' , 'B' , 'C' ) ; } |
|
|
|
| 218.7.185.* |
13楼 刚看到帖子~~!! 有谁可以把代码 和算法相关的思路给我呀! 谢谢~! |
|
|
|
16楼 void move(char x,char y) { printf("%c-->%c\n",x,y); } void hanoi(int n,char one,char two,char three) { if(n==1)move(one,three); else{ hanoi(n-1,one,three,two); move(one,three); hanoi(n-1,two,one,three); } } void main() {int m; printf("input the number of diskes:"); scanf("%d",&m); printf("the step to moving %3d diskes:\n",m); hanoi(m,'A','B','C'); } 目的:把n个东西从A处移动到C处。 分析: 如果只有一个:直接搬过去即可: if(n==1) printf("%c---%c\n",a,c); 否则,把除最下面的那个以外的先放到b处: hanoi(n-1,a,c,b ); 再把最下面的那个搬到c处; 于是问题就变成了:把n-1个东西从b处移动到c处: hanoi(n-1,b,a,c); 递归就开始了…… n-1,n-2,……,2,1 结束 过程大致就是这样。 |
|
|
|
| 123.232.41.* |
18楼 具体为什么是先传A,B,C 再传B,C,A的,这个不需要懂。这是以个实验了很久的答案。不是一个思想就出来的答案。 |
|
|
| 121.28.7.* |
19楼 |
|
|
| 222.16.48.* |
20楼 |
|
|
| 58.213.133.* |
21楼 // 汉诺塔 # include < iostream.h > void hanoi ( int n, char a, char b, char c ) //从主函数接受参数 { if ( n >= 1 ) { hanoi ( n-1, a, c, b ) ; //将上面n-1个盘子从a座借助c座移到b座 cout << a << " --> " << c << endl ; //将最后那个盘子从a移到c hanoi ( n-1, b, a, c ) ; //再将b上那n-1个盘子从b借助a移到c } } void main () { int m ; cout << " Input the number of diskes: " << endl ; cin >> m ; hanoi ( m, 'A' , 'B' , 'C' ) ; //可理解为将n个盘子从A座借助B座移到C座 } 至于中间过程不必管 交给电脑去做吧 |
|
|
|
22楼 void move(char x,char y) { printf("%c-->%c\n",x,y); } void hanoi(int n,char one,char tow,char three) { if(n==1) move(one,three); else { hanoi(n-1,one,three,tow); move(one,three); hanoi(n-1,tow,one,three); } } void main() { int m; printf("input the number of diskes:"); scanf("%d",&m); printf("the step to moving %d diskes:\n",m); hanoi(m,'A','B','C'); } C语言版本~ |
|
|
|
|
24楼 |
|
|
|
| 110.6.99.* |
26楼 |
|
|