讨论 / 谁帮我看看
秋天点点 2008-11-08 19:21:00
点我顶贴 收藏 删除
我的这个用的宽搜

program lx;

const xx:array[1..4] of shortint=(1,0,-1,0);

yy:array[1..4] of shortint=(0,1,0,-1);

type t1=record

x:integer;

y:integer;

fa:integer;

end;

var a:array[1..1000,1..1000] of 0..1;

b:array[1..3000] of t1;

n,x,y,x1,y1,h,t,min,k,i1,j1,i,j:integer;

ch:char;

function same(x,y:integer):boolean;

var i,j,k:integer;

begin

same:=false;

for i:=1 to h-1 do

if (b[i].x=x) and (b[i].y=y) then begin

same:=true;exit;end;

end;

procedure print(l:integer);

var i,j:integer;

begin

if l=1 then exit;

print(b[l].fa);

min:=min+1;

end;

begin

min:=0;

readln(n);

for i:=1 to n do

begin

for j:=1 to n do

begin

read(ch);

if ch=’0’ then a[i,j]:=0

else a[i,j]:=1;

end;

readln;

end;

readln(x,y);

readln(x1,y1);

b[1].x:=x;

b[1].y:=y;

b[1].fa:=0;

h:=1;t:=1;

repeat

for k:=1 to 4 do

begin

i1:=b[t].x+xx[k];

j1:=b[t].y+yy[k];

if (i1 in [1..n]) and (j1 in [1..n]) and (a[i1,j1]=0) then

if not same(i1,j1) then

begin

inc(h);

b[h].x:=i1;

b[h].y:=j1;

b[h].fa:=t;

if (i1=x1) and (j1=y1) then

begin

print(h); writeln(min);close(input);close(output);halt;end;

end;

end;

inc(t);

until t>h;

writeln(0);

end.

怎么回事??

查看更多回复
提交回复