const x:array[1..4] of integer=(-1,1,0,0);
y:array[1..4] of integer=(0,0,-1,1);
maxn=100;
type board=array[1..maxn,1..maxn] of char;
quenetype=record
step:longint;
xx,yy:byte;
end;
var q:array[1..100000] of quenetype;
head,tail:longint;
flag:array[1..maxn,1..maxn] of boolean;
m,n:longint;
map:board;
Procedure Initial;
var i,j:integer;
begin
fillchar(flag,sizeof(flag),false);
head:=1;tail:=1;
q[head].xx:=1;
q[head].yy:=1;
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do
read(map[i,j]);
readln;
end;
end;
Function Judge(qx,qy:byte;i:byte):boolean;
begin
if (qx>0)and(qx<=n)and(qy>0)and(qy<=m) then
exit(true);
exit(false);
end;
Procedure Search(remap:board;qx,qy:byte);
var i,j:byte;
ch:char;
begin
ch:=remap[qx,qy];
remap[qx,qy]:='@';
for i:=1 to n do
for j:=1 to m do
if remap[i,j]=ch then
begin
inc(tail);
q[tail].xx:=i;
q[tail].yy:=j;
q[tail].step:=q[head].step+1;
exit;
end;
end;
Procedure Main;
var i,qx,qy:longint;
begin
while head<=tail do
begin
flag[q[head].xx,q[head].yy]:=true;
for i:=1 to 4 do
begin
qx:=q[head].xx+x[i];
qy:=q[head].yy+y[i];
if judge(qx,qy,i) then
begin
if flag[qx,qy] then continue;
if (qx=n)and(qy=m) then
begin
writeln(q[head].step+1);
halt;
end;
if map[qx,qy]<>'1' then
if map[qx,qy]='0' then
begin
flag[qx,qy]:=true;
inc(tail);
q[tail].xx:=qx;
q[tail].yy:=qy;
q[tail].step:=q[head].step+1;
end
else
search(map,qx,qy)
end;
end;
inc(head);
end;
writeln('No Solution.');
end;
begin
Initial;
Main;
end.
测试结果1: 通过本测试点|有效耗时172ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 通过本测试点|有效耗时46ms
测试结果5: 通过本测试点|有效耗时47ms
测试结果6: 输出过长|用户输出数据超过标准输出两倍[标准输出2位|选手输出12位]
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 通过本测试点|有效耗时203ms
测试结果9: 输出过长|用户输出数据超过标准输出两倍[标准输出3位|选手输出12位]
测试结果10: 输出过长|用户输出数据超过标准输出两倍[标准输出3位|选手输出12位]