记录编号 14702 评测结果 AAAAAAAAAAW
题目名称 [USACO Oct09] 乳草的入侵 最终得分 90
用户昵称 Gravatarrottenwood 是否通过 未通过
代码语言 Pascal 运行时间 0.060 s
提交时间 2009-11-03 15:03:57 内存使用 2.55 MiB
显示代码纯文本
program milkweed;
const
xx:array[1..8] of integer=(-1,-1,0,1,1,1,0,-1);
yy:array[1..8] of integer=(0,1,1,1,0,-1,-1,-1);
var
map:array[1..100,1..100] of string;
i,j,k,m,n,x,y,mx,my,tol:longint;
s1:string;
flag:boolean;
procedure floodfill;
var head,tail,i,j,tou,tailte:longint;
a:array[0..10001,1..2] of longint;
 begin
 fillchar(a,sizeof(a),0);
 a[0,1]:=my; a[0,2]:=mx;
 head:=0;tail:=0;tol:=-1;
 tou:=head;tailte:=tail;
 repeat
  inc(tol);
  tou:=head;
  for k:=head to tail do
  begin
  for i:=1 to 8 do
  begin
   if (a[k,1]+xx[i]<=x)and(a[k,1]+xx[i]>=1)and
      (a[k,2]+yy[i]<=y)and(a[k,2]+yy[i]>=1)
      then
   if (map[a[k,1]+xx[i],a[k,2]+yy[i]]='.') then
    begin
    map[a[k,1]+xx[i],a[k,2]+yy[i]]:='m';
    inc(tailte);
    a[tailte,1]:=a[k,1]+xx[i];
    a[tailte,2]:=a[k,2]+yy[i];
    end;
  end;
  end;
  head:=tail+1;
  tail:=tailte;
 until head>tail;
end;
begin
assign(input,'milkweed.in');reset(input);
assign(output,'milkweed.out');rewrite(output);
readln(y,x,mx,my);
flag:=true;
for i:=1 to x do
 begin
 readln(s1);
 for j:=1 to y do
 map[i,j]:=s1[j];
 end;
map[my,mx]:='m';
floodfill;
for i:=1 to x do
 for j:=1 to y do
  if map[x,y]='.' then flag:=false;
 if flag then writeln(tol) else writeln('-1');
 close(output);
 end.