比赛 20091103 评测结果 AAAAAAAAAAA
题目名称 乳草的入侵 最终得分 100
用户昵称 王瑞祥K 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-03 11:26:09
显示代码纯文本
program milkweed(input,output);
const
 st:array[1..8,1..2]of integer=((-1,0),(1,0),(0,1),(0,-1),(-1,1),(1,-1),(-1,-1),(1,1));
var
 map:array[1..100,1..100]of integer;
 i,j,k,m,n,p,q,tot:integer;
 f:boolean;
 ch:char;
function jiancha:boolean;
var i,j:integer;
begin
 for i:=1 to m do
  for j:=1 to n do
   if map[i,j]=-1 then exit(false);
 exit(true);
end;
procedure kuozhan;
var i,j,k,x,y:integer;
begin
 for i:=1 to m do
  for j:=1 to n do
   if map[i,j]=1 then
    for k:=1 to 8 do begin
     x:=i+st[k,1]; y:=j+st[k,2];
     if (x>=1)and(x<=m)and(y>=1)and(y<=n)then
      if map[x,y]=-1 then map[x,y]:=2;
    end;
 for i:=1 to m do
  for j:=1 to n do
   if map[i,j]=2 then begin map[i,j]:=1;inc(tot);end;
end;
begin
 assign(input,'milkweed.in');assign(output,'milkweed.out');
 reset(input);rewrite(output);
 readln(m,n,p,q);
 fillchar(map,sizeof(map),0);
 for i:=n downto 1 do begin
  for j:=1 to m do begin
   read(ch);
   if ch='.' then map[j,i]:=-1;
  end;
  readln;
 end;
 map[p,q]:=1;
 k:=0; f:=true;
 while not jiancha do begin
  tot:=0;
  inc(k);
  kuozhan;
  if (tot=0)and not jiancha then begin f:=false; break; end;
 end;
 if not f then writeln('-1') else writeln(k);
 close(input);close(output);
end.