×

汉诺塔10层教学视频

汉诺塔10层教学视频(10层的汉诺塔怎么玩)

shqlly shqlly 发表于2022-11-01 19:10:26 浏览62 评论0

抢沙发发表评论

本文目录

10层的汉诺塔怎么玩

/*
给你个程序,你运行一下就知道了 呵呵
*/
# include 《stdio.h》
void hanuota(int n,char a,char b,char c)
{
if (1 == n)
{
printf(“将 %d 从柱子 %c 移动到柱子 %c\n“,n,a,c);
}
else
{
hanuota(n-1,a,c,b);
printf(“将 %d 从柱子 %c 移动到柱子 %c\n“,n,a,c);
hanuota(n-1,b,a,c);
}
}
int main(void)
{
int n;
char a = ’A’;
char b = ’B’;
char c = ’C’;
printf(“请输入所要移动的盘子的层数:“);
scanf(“%d“,&n);
hanuota(n,a,b,c);
return 0;
}

汉诺塔怎么玩

汉诺游戏规则如下:

1、有三根相邻的柱子,标号为A,B,C。

2、A柱子上从下到上按金字塔状叠放着n个不同大小的圆盘。

3、现在把所有盘子一个一个移动到柱子B上,并且每次移动同一根柱子上都不能出现大盘子在小盘子上方。

其实汉诺塔只要掌握规律,多少层都是一样的。

最重要的是第一块放在哪儿,单数层的汉诺塔一定要放在第三柱,双数层的要放在第二柱。

如果你会六层的汉诺塔,(将第一块放在第三柱),将六块都移到第二柱,最后一块移到第三柱,

再如前法将上面六块都移到第三柱。

扩展资料

汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。

大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。

并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。

汉诺塔百度百科

汉诺塔该怎么玩,方法

汉诺塔算法介绍:

一位美国学者发现的特别简单的方法:只要轮流用两次如下方法就可以了。

把三根柱子按顺序排成“品”字型,把所有圆盘按从大到小的顺序放于柱子A上,根据圆盘数量来确定柱子排放的顺序:

n若为偶数的话,顺时针方向依次摆放为:ABC;而n若为奇数的话,就按顺时针方向依次摆放为:ACB。这样经过反复多次的测试,最后就可以按照规定完成汉诺塔的移动。

因此很简单的,结果就是按照移动规则向一个方向移动金片:

如3阶汉诺塔的移动:A→C,A→B,C→B,A→C,B→A,B→C,A→C。

扩展资料:

汉诺塔经典题目:

三根相邻的柱子,标号为A,B,C,A柱子上从下到上按金字塔状叠放着n个不同大小的圆盘,要把所有盘子一个一个移动到柱子B上,且每次移动同一根柱子上都不可以出现大盘子在小盘子上方的情况。

至少需要几次移动的问题,我们设移动次数为H(n)。

把上面n-1个盘子移动到柱子C上,把最大的一块放在B上,把C上的所有盘子移动到B上,由此我们得出表达式:

H⑴ = 1

H(n) = 2*H(n-1)+1 (n》1)

很快我们就可以得到H(n)的一般式为:

H(n) = 2^n - 1 (n》0)

且这种方法的确是最少次数的,证明非常简单,可以尝试从2个盘子的移动开始证,可以试试。

进一步加深问题:

假如现在每种大小的盘子都有两个,并且是相邻的,设盘子个数为2n,问:⑴假如不考虑相同大小盘子的上下要几次移动,设移动次数为J(n);⑵只要保证到最后B上的相同大小盘子顺序与A上时相同,需要几次移动,设移动次数为K(n)。

⑴中的移动相当于是把前一个问题中的每个盘子多移动一次,也就是:

J(n) = 2*H(n) = 2*(2^n - 1) = 2^(n+1)-2

在分析⑵之前,我们来说明一个现象,假如A柱子上有两个大小相同的盘子,上面一个是黑色的,下面一个是白色的,我们把两个盘子移动到B上,需要两次。

盘子顺序将变成黑的在下,白的在上,然后再把B上的盘子移动到C上,需要两次,盘子顺序将与A上时相同,由此我们归纳出当相邻两个盘子都移动偶数次时,盘子顺序将不变,否则上下颠倒。

回到最开始的问题,n个盘子移动,上方的n-1个盘子总移动次数为2*H(n-1),所以上方n-1个盘子的移动次数必定为偶数次,最后一个盘子移动次数为1次。

讨论问题⑵:

综上可以得出,要把A上2n个盘子移动到B上,可以得出上方的2n-2个盘子必定移动偶数次,所以顺序不变,移动次数为:

J(n-1) = 2^n-2

然后再移动倒数第二个盘子,移动次数为2*J(n-1)+1 = 2^(n+1)-3,

最后移动最底下一个盘子,所以总的移动次数为:

K(n) = 2*(2*J(n-1)+1)+1 = 2*(2^(n+1)-3)+1 = 2^(n+2)-5

汉诺塔(益智玩具)-百度百科

史上最难智力游戏汉诺塔怎么过

通关步骤:

1.如下图所示:柱子从左到右设为:ABC ;环从小到大设为:12345;

2.移动方法:

1→C,2→B,1→B,3→C,1→A,2→C,1→C,4→B;

1→B,2→A,1→A,3→B,1→C,2→B,1→B,5→C;

1→A,2→C,1→C,4→A,1→B,2→A,1→A,4→C; 

1→C,2→B,1→B,3→C,1→A,2→C,1→C,完成!

拓展资料:

  1. 汉诺塔:(又称河内塔)问题是源于印度一个古老传说的益智玩具。大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。

  2. 大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。

  3. 有预言说,这件事完成时宇宙会在一瞬间闪电式毁灭。也有人相信婆罗门至今还在一刻不停地搬动着圆盘。

七层的汉诺塔怎么玩

汉诺塔算法介绍:
把三根柱子按顺序排成“品”字型,把所有圆盘按从大到小的顺序放于柱子A上,根据圆盘数量来确定柱子排放的顺序:n若为偶数的话,顺时针方向依次摆放为:ABC;而n若为奇数的话,就按顺时针方向依次摆放为:ACB。
这样经过反复多次的测试,最后就可以按照规定完成汉诺塔的移动。因此很简单的,结果就是按照移动规则向一个方向移动金片:如3阶汉诺塔的移动:A→C,A→B,C→B,A→C,B→A,B→C,A→C。

递归算法 汉诺塔 演示

TurboC 1024×768 真彩色,演示全木质汉诺塔
ESC 退出, 空格切换 自动手动
tc 2.0, 3.0 均可运行
#include 《dos.h》
#include 《fcntl.h》
#include 《io.h》
#include 《math.h》
#include 《stdio.h》
#include 《conio.h》
#include 《stdlib.h》
#define MINDISK 1
#define MAXDISK 15
#define DISKHEIGHT 30
#define TEXT_BIG_CURSOR 0
#define TEXT_NORMAL_CURSOR 7
typedef struct /*16Mrgb像素类型*/
{
unsigned char b;
unsigned char g;
unsigned char r;
}rgb16M;
typedef struct tagDisks
{
int x;
int y;
int Left;
int Top;
int Lenth;
int Height;
int Tag;
int Cylinder1;
int Cylinder2;
int Cylinder3;
}Disks;
void DrawPillar(int number, int bottom);
void DrawDisk(int x, int y, int lenth, int height);
void HanoiMove(int n, int X, int Y, int Z);
void MoveDisk(int n, int DiskFrom, int DiskTo);
void SetXY(Disks *disk, int nX, int nY, int cleardisk);
int disk_num;
int automove = 1;
int toquit = 0;
int delayperiod;
int CylinderHeight;
Disks disks;
rgb16M backcolor = {140, 197, 227}, backcolor1 = {34, 95, 149};
rgb16M woodcolor = {{{180, 223, 240},{138, 205, 230},{98, 188, 222},{58, 171, 214}},{{2, 96,132},{4,110,151},{3, 121, 166},{4, 135, 183}}};
rgb16M bordercolor = {52, 128, 203};
long woodfillcolor = {
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1},
{0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x53B2F1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1,0x62B3F1,0x43A3E3,0x43ABF1,0x43ABF1,0x53B2F1,0x62B3F1,0x43A3E3,0x43ABF1}};
unsigned char set_SVGA_mode(int vmode)
{union REGS r;
r.x.ax=0x4f02;
r.x.bx=vmode;
int86(0x10,&r,&r);
return(r.h.ah);
}
void hide_text_cursor(void)
{union REGS r;
r.h.ah=1;
r.h.ch=32;
int86(0x10,&r,&r);
}
void selectpage(register char page)
{union REGS r;
r.x.ax=0x4f05;
r.x.bx=0;
r.x.dx=page;
int86(0x10,&r,&r);
}
void show_text_cursor(char size)
{union REGS r;
r.h.ah=1;
r.h.cl=size;
r.h.ch=7;
int86(0x10,&r,&r);
}
unsigned int get_SVGA_mode()
{union REGS r;
r.x.ax=0x4f03;
int86(0x10,&r,&r);
return(r.x.bx);
}
unsigned int Vmode=0;
void init16M()
{Vmode=get_SVGA_mode();
hide_text_cursor();
if(set_SVGA_mode(0x118))
{printf(“\nSorry, Your graphics driver does not supplied.\n“);
show_text_cursor(TEXT_NORMAL_CURSOR);
exit(0);
}
}
void close16M()
{
union REGS r;
r.h.ah = 0;
r.h.al = 3;
int86(0x10, &r, &r);
r.h.ah = 0x05;
r.h.al = 0;
int86(0x10, &r, &r);
}
void putpoint16M(int x, int y, rgb16M color)
{
static int nowpage = 0, lastpage = 50;
static long temp;
unsigned char far *p = (unsigned char *)0xa0000000;
temp = y;
x 《《= 2;
temp 《《= 12;
temp += x;
nowpage = temp 》》 16;
temp &= 0xffff;
if (nowpage != lastpage)
{
static union REGS r;
r.x.ax = 0x4f05;
r.x.bx = 0;
r.x.dx = nowpage;
int86(0x10, &r, &r);
lastpage = nowpage;
}
*((rgb16M *)(p + temp)) = color;
}
void line(int startx, int starty, int endx, int endy, rgb16M color)
{
register int t, distance;
int x = 0, y = 0;
int delta_x, delta_y;
int incx, incy;
delta_x = endx-startx;
delta_y = endy-starty;
if (delta_x 》 0) incx = 1;
else if(delta_x == 0) incx = 0;
else incx = -1;
if(delta_y 》 0) incy = 1;
else if (delta_y == 0) incy = 0;
else incy = -1;
if (delta_x 《 0) delta_x = -delta_x;
if (delta_y 《 0) delta_y = -delta_y;
if(delta_x 》 delta_y) distance = delta_x;
else distance = delta_y;
for (t = 0; t 《= distance + 1; t++){
putpoint16M(startx, starty, color);
x += delta_x;
y += delta_y;
if (x 》 distance){
x -= distance;
startx += incx;
}
if(y 》 distance){
y -= distance;
starty += incy;
}
}
}
void fillbox(int startx, int starty, int endx, int endy, rgb16M color)
{
int i, j;
if (startx 》 endx)
{
i = startx;
startx = endx;
endx = i;
}
if (starty 》 endy)
{
i = starty;
starty = endy;
endy = i;
}
if (startx 《 0)
startx = 0;
if (endx 》 1023)
endx = 1023;
if (starty 《 0)
starty = 0;
else if (endy 》 767)
endy = 767;
for (j = starty; j 《= endy; j++)
for (i = startx; i 《= endx; i++)
putpoint16M(i, j, color);
}
int main(void)
{
int i, j;
int left, top;
int width = 975;
int height = 600;
reinnum:;
printf(“input the number of disk(%d-%d, 0 to quit): “, MINDISK, MAXDISK);
delayperiod = 500;
scanf(“%d“, &disk_num);
if (disk_num == 0)
return 0;
if (disk_num 《 MINDISK || disk_num 》 MAXDISK)
goto reinnum;
printf(“select play style(0:auto, 1:manual): “);
scanf(“%d“, &automove);
if (automove != 0)
automove = 1;
if (automove == 0)
{
reintime:;
printf(“input the delay period(100-5000): “);
scanf(“%d“, &delayperiod);
if (delayperiod 《 100 || delayperiod 》 5000)
goto reintime;
}
init16M();
left = (1024 - width) 》》 1;
top = (768 - height) 》》 1;;
fillbox(left, top, left + width, top + height, backcolor1);
fillbox(left - 10 , top - 12, left - 2, top + height + 13, bordercolor);
fillbox(left + width + 2, top - 12, left + width + 10, top + height + 13, bordercolor);
fillbox(left, top - 12, left + width, top - 2, bordercolor);
fillbox(left, top + height + 2, left + width, top + height + 13, bordercolor);
for (i = 0; i 《 3; i++)
CylinderHeight = 0;
disks.Cylinder1 = left + width / 6;
disks.Cylinder2 = left + width / 2;
disks.Cylinder3 = left + width / 6 * 5;
DrawPillar(1, 0);
DrawPillar(2, 0);
DrawPillar(3, 0);
DrawDisk(disks.Cylinder1 - ((width / 4) + 7) / 2 - 20, 673, (width / 4) + 47, 12);
DrawDisk(disks.Cylinder2 - ((width / 4) + 7) / 2 - 20, 673, (width / 4) + 47, 12);
DrawDisk(disks.Cylinder3 - ((width / 4) + 7) / 2 - 20, 673, (width / 4) + 47, 12);
for (i = disk_num; i 》= 1; i--)
{
disks.x = 1;
disks.y = i;
disks.Cylinder1 = left + width / 6;
disks.Cylinder2 = left + width / 2;
disks.Cylinder3 = left + width / 6 * 5;
disks.Height = DISKHEIGHT;
disks.Tag = i;
disks.Lenth = (width / 4 / disk_num * i) + 7;
SetXY(&disks, 0);
CylinderHeight++;
}
getch();
HanoiMove(disk_num, 1, 2, 3);
getch();
close16M();
return 0;
}
void DrawPillar(int number, int bottom)
{
int x, y = 110;
int lenth = 8, height;
int i, j, m, n;
if (number == 1)
x = disks.Cylinder1 - 4;
else if (number == 2)
x = disks.Cylinder2 - 4;
else
x = disks.Cylinder3 - 4;
if (bottom == 0)
height = 575;
else
height = bottom;
m = 0;
n = 0;
for (i = y + 4; i 《= y + height - 1 && i 《 bottom; i++)
{
for (j = x + 4; j 《= x + lenth - 5; j++)
{
woodcolor;
woodcolor)》》8);
woodcolor》》16);
putpoint16M(j, i, woodcolor);
m++;
if (m 》 29)
m = 0;
}
m = 0;
n++;
if (n 》 34)
n = 0;
}
woodcolor = backcolor;
for (i = 0 ; i 《 4; i++)
{
line(x + i, y + i, x + i, y + height - 1, woodcolor);
line(x + i + 1, y + i, x + lenth - i - 1, y + i, woodcolor);
line(x + lenth - i - 1, y + i, x + lenth - i - 1, y + height - 1, woodcolor);
}
}
void DrawDisk(int x, int y, int lenth, int height)
{
int i, j, m, n;
woodcolor = backcolor;
for (i = 0 ; i 《 4; i++)
{
line(x + i, y + i, x + i, y + height - i - 1, woodcolor);
line(x + i + 1, y + i, x + lenth - i - 1, y + i, woodcolor);
line(x + i + 1, y + height + i - 4, x + lenth - 1, y + height + i - 4, woodcolor);
line(x + lenth - i - 1, y + i, x + lenth - i - 1, y + height - 4, woodcolor);
}
m = 0;
n = 0;
for (i = y + 4; i 《= y + height - 5; i++)
{
for (j = x + 4; j 《= x + lenth - 5; j++)
{
woodcolor;
woodcolor)》》8);
woodcolor》》16);
putpoint16M(j, i, woodcolor);
m++;
if (m 》 29)
m = 0;
}
m = 0;
n++;
if (n 》 34)
n = 0;
}
}
void MoveDisk(int n, int DiskFrom, int DiskTo)
{
if (toquit == 1)
return;
SetXY(&disks, 1);
CylinderHeight--;
CylinderHeight++;
}
void SetXY(Disks *disk, int nX, int nY, int cleardisk)
{
if (cleardisk == 1)
{
fillbox(disk-》Left, disk-》Top, disk-》Left + disk-》Lenth - 1, disk-》Top + disk-》Height - 1, backcolor1);
DrawPillar(disk-》x, DISKHEIGHT - 35 + 599 - disk-》Height * CylinderHeight - 1);
}
disk-》x = nX;
disk-》y = nY;
switch (nX)
{
case 1 :
disk-》Left = disk-》Cylinder1 - disk-》Lenth / 2;
break;
case 2 :
disk-》Left = disk-》Cylinder2 - disk-》Lenth / 2;
break;
case 3 :
disk-》Left = disk-》Cylinder3 - disk-》Lenth / 2;
break;
default :
;
}
disk-》Top = 35 - DISKHEIGHT + 638 - disk-》Height * disk-》y;
DrawDisk(disk-》Left, disk-》Top, disk-》Lenth, disk-》Height);
}
void HanoiMove(int n, int X, int Y, int Z)
{
int a;
if (n == 0 || toquit == 1)
return;
HanoiMove(n - 1, X, Z, Y);
MoveDisk(n, X, Z);
if (toquit == 1)
return;
if (automove == 1)
{
a = getch();
if (a == 0)
{
a = getch();
}
else if (a == 27)
{
toquit = 1;
return;
}
else if (a == 32)
{
automove = 1 - automove;
}
}
else
{
if (kbhit())
{
a = getch();
if (a == 27)
{
toquit = 1;
return;
}
else if (a == 32)
{
automove = 1 - automove;
}
}
delay(delayperiod);
}
HanoiMove(n - 1, Y, X, Z);
}

史上最难智力游戏汉诺塔怎么破

根据游戏规律:

三层四层,十层二十层,无论多少层,套路都是一样的,只不过多一层麻烦程度会大大增加。

假设:五层,A,B,C三个柱子。从A到C。
套路就是:先把上面四层移到B,然后第五层到C,然后再把B的那前四层移到C。
同理,四层到B也可以拆分成前三层到C+第四层到B。
就这么无限循环循环就结束了啊。原理很简单。

其实原理大概是这样的:

从上往下数12345为代号,三根柱子的代号是abc.

1往c放,2往b放,1往b放,3往c放,1往a放,2往c放,1往c放,4往b放,1往b放,2往a放,1往a放,3往b放,1往c放,2往b放,1往b放,5往c放,1往a放,2往c放,1往c放,3往a放,1往b放,2往a放,1往a放,4往c放,1往c放,2往b放,1往b放,3往c放,1往b放,2往c放,1往c放。

汉诺塔游戏规则

汉诺游戏规则如下:

1、有三根相邻的柱子,标号为A,B,C。

2、A柱子上从下到上按金字塔状叠放着n个不同大小的圆盘。

3、现在把所有盘子一个一个移动到柱子B上,并且每次移动同一根柱子上都不能出现大盘子在小盘子上方。

其实汉诺塔只要掌握规律,多少层都是一样的。

最重要的是第一块放在哪儿,单数层的汉诺塔一定要放在第三柱,双数层的要放在第二柱。

如果你会六层的汉诺塔,(将第一块放在第三柱),将六块都移到第二柱,最后一块移到第三柱,

再如前法将上面六块都移到第三柱。

扩展资料

汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。

大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。

并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。

汉诺塔百度百科