WHY I GOT "WA"??? Heeeeelp!
Послано
Serrg 19 мар 2003 00:53
const z:array[1..8,1..2]of integer=((-1,-1),(-1,0),(-1,1),(0,1),
(1,1),(1,0),(1,-1),(0,-1));
var
tab:array[0..76,0..76] of boolean;
r:array[1..75,1..75] of real;
v,q2,sum,psum:real;
i,j,jj,k,x0,y0,x,y:integer;
m,n:integer;
c:char;
procedure find;
type rec=record
x,y:integer;
end;
var i,j,top1,top2:integer;
st1,st2:array[1..1700] of rec;
a1,a2:integer;
begin
top1:=1;
top2:=0;
st1[1].x:=x0;
st1[1].y:=y0;
repeat
for i:=1 to top1 do begin
if (st1[i].x=x)and(st1[i].y=y) then begin
sum:=sum+r[x,y];
exit;
end;
for j:=1 to 8 do begin
a1:=st1[i].x+z[j,1];
a2:=st1[i].y+z[j,2];
if (tab[a1,a2]=false)and(r[a1,a2]<0) then begin
inc(top2);
st2[top2].x:=a1;
st2[top2].y:=a2;
if (z[j,1]<>0)and(z[j,2]<>0) then r[a1,a2]:=r[st1[i].x,st1[i].y]
+q2
else r[a1,a2]:=r[st1[i].x,st1[i].y]+1;
end;
end;
end;
st1:=st2;
top1:=top2;
top2:=0;
until top1=0;
end;
begin
q2:=sqrt(2);
readln(m,n,k,v);
for i:=0 to n+1 do
for j:=0 to m+1 do
tab[i,j]:=true;
for i:=1 to n do begin
for j:=1 to m do begin
read(c);
if c='.' then tab[i,j]:=false;
end;
readln;
end;
readln(y0,x0);
for i:=1 to k do begin
for j:=1 to n do
for jj:=1 to m do
r[j,jj]:=-1;
readln(y,x);
r[x0,y0]:=0.0000001;
psum:=sum;
find;
if abs(sum-psum)>0.5 then begin
x0:=x;
y0:=y;
end;
end;
sum:=sum/v;
writeln(sum:0:2);
end.