讨论 / 大牛请帮忙看一下,这段程序哪错了
cc^0^ 2012-11-06 23:11:00
点我顶贴 收藏 删除
type list=record

l,nu:longint;

da:string;

end;

var s,t,s1:string;

ans,num,x:longint;

q:array[0..1000000]of list;

v:array[0..10000]of boolean;

p:list;

procedure init;

var i,j:longint;

begin

readln(s);

t:='123804765';

i:=length(s);

for j:=1 to i do if s[j]='0' then num:=j;

for j:=1 to 10000 do

begin

q[j].l:=0;q[j].da:='';q[j].nu:=0;

end;

fillchar(v,sizeof(v),1);

end;

procedure find(w:string);

var i,j:longint;

begin

x:=0;

for i:=1 to length(w) do

x:=x+ord(w[i])*i;

end;

procedure main;

var i,j,l,r:longint;ch:char;f:boolean;

begin

l:=1;r:=1;

q[r].da:=s;q[r].l:=0;q[r].nu:=num; find(q[r].da);v[x]:=false;

while l<=r do

begin

f:=false;

for i:=1 to 4 do

begin

case i of

1:begin//上

if q[l].nu>3 then

begin

p:=q[l];

p.nu:=p.nu-3;

ch:=p.da[p.nu];

p.da[p.nu]:='0';

p.da[p.nu+3]:=ch;

inc(p.l);

f:=true;

end;

end;

2:begin//下

if q[l].nu<7 then

begin

p:=q[l];

p.nu:=p.nu+3;

ch:=p.da[p.nu];

p.da[p.nu]:='0';

p.da[p.nu-3]:=ch;

inc(p.l);

f:=true;

end;

end;

3:begin//左

if (q[l].nu<>1)and(q[l].nu<>4)and(q[l].nu<>7) then

begin

p:=q[l];

p.nu:=p.nu-1;

ch:=p.da[p.nu];

p.da[p.nu]:='0';

p.da[p.nu+1]:=ch;

inc(p.l);

f:=true;

end;

end;

4:begin//右

if (q[l].nu<>3)and(q[l].nu<>6)and(q[l].nu<>9) then

begin

p:=q[l];

p.nu:=p.nu+1;

ch:=p.da[p.nu];

p.da[p.nu]:='0';

p.da[p.nu-1]:=ch;

inc(p.l);

f:=true;

end;

end;

end;

if f then begin

find(p.da);

if v[x] then

begin

inc(r);

q[r]:=p;

v[x]:=false;

if q[r].da=t then

begin

write(q[r].l);

exit;

end;

end;end;

end;

inc(l);

end;

end;

begin

// assign(input,'bashuma.in');reset(input);

//assign(output,'bashuma.out');rewrite(output);

init;

main;

// close(input);close(output);

end.

查看更多回复
提交回复