讨论 / 求救!
lsdygxx 2017-08-04 15:15:05
点我顶贴 收藏 删除
60分代码

var

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

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

m,n,i,j,s,ans,n1,m1,n2,m2:integer;

a:array[0..101,0..101]of integer;

b:array[0..101,0..101]of boolean;

procedure dfs(x,y,k,p:integer);

var

i:integer;

begin

if (x=m2)and(y=n2) then begin

if p<ans then ans:=p;

exit;

end;

for i:=1 to 4 do

if (a[qx[i]+x,qy[i]+y]=0)and(qx[i]+x>0)and(qx[i]+x<=m)and(qy[i]+y>0)and(qy[i]+y<=n)and(b[qx[i]+x,qy[i]+y])

then begin

b[qx[i]+x,qy[i]+y]:=false;

if i<>k then dfs(qx[i]+x,qy[i]+y,i,p+1)

else dfs(qx[i]+x,qy[i]+y,i,p);

b[qx[i]+x,qy[i]+y]:=true;

end;

end;

begin

readln(m,n);

for i:=1 to m do

for j:=1 to n do

read(a[i,j]);

read(m1,n1,m2,n2);

fillchar(b,sizeof(b),true);

b[m1,n1]:=false;

ans:=10000;

dfs(m1,n1,1,0);

if ans=10000 then ans:=0;

if ans=0 then write(ans)

else write(ans-1);

end.

#1 孙晓鸥@2017-08-06 21:37:04
回复 删除
那一道题?
查看更多回复
提交回复