
游戏中的每一步规则如下:
1. 每一步只允许移动一个盘子(从一根柱子最上方到另一个柱子的最上方)
2. 移动的过程中,你必须保证大的盘子不能在小的盘子上方(小的可以放在大的上面,最大盘子下面不能有任何其他大小的盘子)
如对于n=3的情况,一个合法的移动序列式:
1 from A to C
2 from A to B
1 from C to B
3 from A to C
1 from B to A
2 from B to C
1 from A to C
给出一个数n,求出最少步数的移动序列
通过的进!!
var n,i,z:longint;
procedure h(n:longint;a,b,c:char);
begin
if n=1 then writeln(n,' from ',a,'薯咐 to ',c)
else
begin
h(n-1,a,c,b);
writeln(n,' from ',a,' to ',c);
h(n-1,b,a,c);
end;
end;
begin
readln(n);
z:=1;
for i:=1 to n do
z:=z*2;
dec(z);
writeln(z);
h(n,'A','B','C'数辩纯);
end.
本程序已经AC,望采纳,也希望交个朋友,本灶谨人浙江神死魔灭
var
n,i:longint;
procedure move(n:longint;a,b,c:char);
begin
if n=1 then begin writeln(a,'-->',c);inc(i);end
else begin
move(n-1,a,c,b);
writeln(a,'-->',c);inc(i);
move(n-1,b,a,c);
end;
end;
begin
readln(n);
move(n,'手兆厅A','B'猜唤,'C'毕隐);
end.
望采纳!!!
楼上有个很明显的错误啊,帕斯卡拉语言,至少一开始得有个兄银
PROGRAM move(input,桥尘好output)敏铅吧