田田 @ 2018-05-12 17:33:00
var i,j,n,ans,x1,y1,x2,y2,head,tail:longint; aa:char; x,y:array[0..10000] of longint; p:array[0..1000,0..1000] of boolean; d:array[1..4,1..2] of integer=((1,0),(-1,0),(0,1),(0,-1)); Procedure bfs; var k,i,j,t:longint; begin inc(ans); t:=tail; for k:=head to tail do for i:=1 to 4 do begin if (x[k]+d[i,1]=x2) and (y[k]+d[i,2]=y2) then begin writeln(ans); halt; end; if p[x[k]+d[i,1],y[k]+d[i,2]] then if (x[k]+d[i,1]>0) and (x[k]+d[i,1]<=n) and (y[k]+d[i,2]>0) and (y[k]+d[i,2]<=n) then begin inc(tail); x[tail]:=x[k]+d[i,1]; y[tail]:=y[k]+d[i,2]; p[x[tail],y[tail]]:=false; end; end; head:=t+1; bfs; end; begin fillchar(p,sizeof(p),true); readln(n); for i:=1 to n do begin for j:=1 to n do begin read(aa); if aa='1' then p[i,j]:=false; end; readln; end; readln(x1,y1,x2,y2); head:=1; tail:=1; x[1]:=x1; y[1]:=y1; p[x1,y1]:=false; bfs; end.
by Rbu_nas @ 2018-05-12 17:36:03
by autoint @ 2018-05-12 17:59:15
呵呵,还真是给“大佬”看的