a1:array[0..101,0..101]of char;
a2:array[1..10000,1..3]of integer;
a3:array[1..100,1..100]of boolean;
i,e,f,p,m,n,x,y,en:longint;
procedure ins(a,b:longint);
var
j,k:longint;
bool:boolean;
begin
bool:=true;
if a3[a,b] then
if a1[a,b]=0 then
begin
inc(en);
a2[en,1]:=a;
a2[en,2]:=b;
a2[en,3]:=a2[i,3]+1;
a3[a,b]:=false;
exit;
end
else if a1[x,y]<>1 then
begin
for j:=1 to m do
for k:=1 to n do
if (a1[j,k]=a1[a,b])and((j<>a)or(k<>b))then
begin
inc(en);
a2[en,1]:=j;
a2[en,2]:=k;
a2[en,3]:=a2[i,3]+1;
a3[a,b]:=false;
exit;
end;
end;
end;
begin
readln(m,n);
for i:=1 to m do
begin
for p:=1 to n do
read(a1[i,p]);
readln;
end;
for i:=1 to m do
begin
a1[i,0]:=1;
a1[i,n+1]:=1;
end;
for i:=1 to n do
begin
a1[0,i]:=1;
a1[m+1,i]:=1;
end;
a2[1,1]:=1;
a2[1,2]:=1;
a2[1,3]:=0;
e:=1;f:=1;
en:=1;
fillchar(a3,sizeof(a3),true);
a3[1,1]:=false;
repeat
for i:=f to e do
begin
x:=a2[i,1]+1;
y:=a2[i,2];
ins(x,y);
x:=x-2;
ins(x,y);
x:=x+1;
y:=y-1;
ins(x,y);
y:=y+2;
ins(x,y);
if not(a3[m,n]) then begin write(a2[en,3]);halt;end;
end;
f:=e+1;
e:=en;
until f>e;
write(No Solution.);
end.
var
a1:array[0..101,0..101]of char;
a2:array[1..10000,1..3]of longint;
i,e,f,p,m,n,x,y,en:longint;
procedure HJ2(a,b:longint);
var
j,k:longint;
bool:boolean;
begin
bool:=true;
for j:=1 to en do
if (a2[j,1]=x)and(a2[j,2]=y) then begin bool:=false;break;end;
if bool then
if a1[x,y]="0" then
begin
inc(en);
a2[en,1]:=x;
a2[en,2]:=y;
a2[en,3]:=a2[i,3]+1;
exit;
end
else if a1[x,y]<>"1" then
begin
for j:=1 to m do
for k:=1 to n do
if (a1[j,k]=a1[x,y])and((j<>x)or(k<>y))then
begin
inc(en);
a2[en,1]:=j;
a2[en,2]:=k;
a2[en,3]:=a2[i,3]+1;
exit;
end;
end;
end;
begin
readln(m,n);
for i:=1 to m do
begin
for p:=1 to n do
read(a1[i,p]);
readln;
end;
for i:=1 to m do
begin
a1[i,0]:="1";
a1[i,n+1]:="1";
end;
for i:=1 to n do
begin
a1[0,i]:="1";
a1[m+1,i]:="1";
end;
a2[1,1]:=1;
a2[1,2]:=1;
a2[1,3]:=0;
e:=1;f:=1;
en:=1;
repeat
for i:=f to e do
begin
x:=a2[i,1]+1;
y:=a2[i,2];
HJ2(x,y);
x:=x-2;
HJ2(x,y);
x:=x+1;
y:=y-1;
HJ2(x,y);
y:=y+2;
HJ2(x,y);
for p:=1 to en do if (a2[p,1]=m)and(a2[p,2]=n) then begin writeln(a2[p,3]);halt;end;
end;
f:=e+1;
e:=en;
until f>e;
write("No Solution.");
end.
将"转为