比赛 20091103 评测结果 C
题目名称 乳草的入侵 最终得分 0
用户昵称 bly1991 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-03 11:43:48
显示代码纯文本
program bly(input,output);
var
  map:array[0..100,0..100] of char;
  time:integer;
  x,y,x0,y0:integer;
  p,p0:boolean;
  i,j:integer;
  f1,f2:text;

  procedure pd;
  begin
    p0:=false;
    for i:=1 to y do begin
      for j:=1 to x do begin
        if map[i,j]='.' then p0:=true;
      end;
    end;
  end;


  procedure int;
  begin
    p:=false;
    if (map[i+1,j]<>'*')and(i+1<=x) then begin
      map[i+1,j]:='M';
      p:=true;
    end;
    if (map[i,j+1]<>'*')and(j+1<=y) then begin
      map[i,j+1]:='M';
      p:=true;
    end;
    if (map[i+1,j+1]<>'*')and(i+1<=x)and(j+1<=y) then begin
      map[i+1,j+1]:='M';
      p:=true;
    end;
    if (map[i-1,j]<>'*')and(i-1>0) then begin
      map[i-1,j]:='M';
      p:=true;
    end;
    if (map[i,j-1]<>'*')and(j-1>0) then begin
      map[i,j-1]:='M';
      p:=true;
    end;
    if (map[i-1,j-1]<>'*')and(i-1>0)and(j-1>0) then begin
      map[i-1,j-1]:='M';
      p:=true;
    end;
    if (map[i+1,j-1]<>'*')and(i+1<=x)and(j-1>0) then begin
      map[i+1,j-1]:='M';
      p:=true;
    end;
    if (map[i-1,j+1]<>'*')and(i-1>0)and(j+1<=y) then begin
      map[i-1,j+1]:='M';
      p:=true;
    end;
  end;
begin
  assign(f1,'milkweed.in');
  reset(f1);
  readln(f1,x,y,x0,y0);
  for i:=1 to y do begin
    for j:=1 to x do begin
      read(f1,map[i,j]);
    end;
    readln(f1);
  end;
  close(f1);

  map[x0,y0]:='M';
  repeat
    pd;
    for i:=1 to y do begin
      for j:=1 to x do begin
        if map[i,j]='M' then
          int;
        end;
      end;
    end;
  until (p=false)or(p0=false);
  assign(f2,'milkweed.out');
  rewrite(f2);
  if p=false then writeln(time);
  if p0=false then writeln('-1');
  close(f2);
end.