讨论 / 为啥只对了2个点,这道题我做过类似的,过了,为什么这题过不了。
施支林 2017-03-03 18:03:57
点我顶贴 收藏 删除
Var

a:array[1..1000,1..1000]of boolean;

n,head,i,j,tail,x1,x2,y1,y2:integer;

ch:boolean;

s:string;

h,l,bz,father:array[1..100000]of integer;

f:array[1..4,1..2]of integer=((1,0),(0,1),(-1,0),(0,-1));

Begin

readln(n);

for i:=1 to n do

begin

readln(s);

for j:=1 to length(s) do

if s[j]='0' then

a[i,j]:=true;

end;

readln(x1,y1);

readln(x2,y2);

head:=0; tail:=1;

h[1]:=x1; l[1]:=y1;

bz[1]:=0;

repeat

inc(head);

for i:=1 to 4 do

begin

ch:=false;

if (h[head]+f[i,1]>=1) and (h[head]+f[i,1]<=n) and

(l[head]+f[i,2]>=1) and (l[head]+f[i,2]<=n) and

(a[h[head]+f[i,1],l[head]+f[i,2]]) then

ch:=true;

if (h[head]+f[i,1]=x2) and (l[head]+f[i,2]=y2) then

begin

writeln(bz[head]+1);

readln;

exit;

end;

if ch then

begin

inc(tail);

h[tail]:=h[head]+f[i,1];

l[tail]:=l[head]+f[i,2];

father[tail]:=head;

a[h[tail],l[tail]]:=false;

bz[tail]:=bz[head]+1;

end;

end;

until head>=tail;

End.

查看更多回复
提交回复