讨论 / BFD SOS!!! wrong 201!!
583158450 2011-10-03 21:34:00
点我顶贴 收藏 删除
const

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

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

type

st=ansistring;

arr=array[0..1000,0..1000]of integer;

arr1=array[1..10000]of integer;

var

a:arr;

s:st;

x,y:arr1;

n,i,j,ans,top,head,x1,y1,x2,y2:longint;

begin

readln(n);

for i:=1 to n do

begin

readln(s);

for j:=1 to n do

if s[j]='1' then a[i,j]:=-1

else a[i,j]:=0;

end;

for i:=1 to n do

begin

a[0,i]:=-1;

a[i,0]:=-1;

a[n+1,i]:=-1;

a[i,n+1]:=-1;

end;

read(x1,y1,x2,y2);

a[x1,y1]:=1;

top:=1;head:=1;

xx[top]:=x1;yy[top]:=y1;

repeat

for i:=head to top do

begin

for j:=1 to 4 do

if a[x[i]+xx[j],y[i]+yy[j]]=0 then

begin

a[x[i]+xx[j],y[i]+yy[j]]:=a[x[i],y[i]]+1;

inc(top);

x[top]:=x[i]+xx[j];

y[top]:=y[i]+yy[j];

if (x[top]=x2)and(y[top]=y2)then

begin write(a[x[top],y[top]]); halt; end;

end;

inc(head);

end;

until head>top;

for i:=1 to n do

for j:=1 to n do

if j=n then writeln(a[i,j])

else write(a[i,j]);

end.

#1 ·August·@2011-10-03 21:34:00
回复 删除
arr1=array[1..10000]of integer;

arr1=array[1..1000000]of integer;

有1000*1000=1000000

查看更多回复
提交回复