记录编号 14731 评测结果 AAAAAAAAAAW
题目名称 [USACO Oct09] 乳草的入侵 最终得分 90
用户昵称 Gravatar打不死的羊 是否通过 未通过
代码语言 Pascal 运行时间 0.016 s
提交时间 2009-11-03 20:12:28 内存使用 0.89 MiB
显示代码纯文本
program milkweed;
const
cx:array[1..8] of longint=(0,0,1,1,1,-1,-1,-1);
cy:array[1..8] of longint=(1,-1,1,-1,0,1,-1,0);
type
fxz1=array[1..100,1..100]of boolean;
fxz2=array[1..100000] of longint;
var
f1,f2:text;
i,j,n,m,x,y,ans,t,w,ww,shi:longint;
ch:char;
map:fxz1;
xx,yy:fxz2;
begin assign(f1,'milkweed.in');
      assign(f2,'milkweed.out');
      reset(f1);rewrite(f2);
      readln(f1,m,n,y,x);
      for i:=1 to n do
      for j:=1 to m do map[i,j]:=false;
      shi:=0;
      for i:=1 to n do
      begin for j:=1 to m do
            begin read(f1,ch);
                  if ch='.' then map[i,j]:=true
                            else inc(shi);

             end;
            readln(f1);
      end;
      xx[1]:=x;yy[1]:=y;t:=1;w:=1;
      ans:=-1;
      repeat inc(ans);
             ww:=w;
             for i:=t to w do
             for j:=1 to 8 do if (xx[i]+cx[j]>0)and(xx[i]+cx[j]<=n)and(yy[i]+cy[j]>0)and(yy[i]+cy[j]<=m) then
                              if map[xx[i]+cx[j],yy[i]+cy[j]] then
                              begin inc(ww);
                                    xx[ww]:=xx[i]+cx[j];
                                    yy[ww]:=yy[i]+cy[j];
                                    map[xx[i]+cx[j],yy[i]+cy[j]]:=false;
                              end;
             t:=w+1;
             w:=ww;

      until t>w;
      if w<n*m-shi then ans:=-1;
      writeln(f2,ans);
      close(f1);close(f2);
end.