记录编号 7497 评测结果 ATAATTTTTT
题目名称 [BYVoid S1] 血色叛徒 最终得分 30
用户昵称 Gravatarbly1991 是否通过 未通过
代码语言 Pascal 运行时间 7.325 s
提交时间 2008-11-10 16:27:57 内存使用 1.55 MiB
显示代码纯文本
program bly(input,output);
var
  a:array[0..500,0..500] of integer;
  b:array[1..250000,1..2] of integer;
  long,x,y,a0,b0,n,m:integer;
  i,j:longint;
  f1,f2:text;

  procedure kz(x0,y0:integer);
  begin
    if (x0=0)and(y0=0) then exit
      else begin
        if (a[x0,y0]+1<a[x0-1,y0])and(x0-1>=0) then begin
          a[x0-1,y0]:=a[x0,y0]+1;
          kz(x0-1,y0);
        end;
        if (a[x0,y0]+1<a[x0,y0-1])and(y0-1>=0) then begin
          a[x0,y0-1]:=a[x0,y0]+1;
          kz(x0,y0-1);
        end;
        if (a[x0,y0]+1<a[x0+1,y0])and(x0+1<=n) then begin
          a[x0+1,y0]:=a[x0,y0]+1;
          kz(x0+1,y0);
        end;
        if (a[x0,y0]+1<a[x0,y0+1])and(y0+1<=m) then begin
          a[x0,y0+1]:=a[x0,y0]+1;
          kz(x0,y0+1);
        end;
      end;
  end;
begin
  for i:=1 to 500 do
    for j:=1 to 500 do
      a[i,j]:=maxint;
  assign(f1,'crusade.in');
  reset(f1);
  readln(f1,n,m,a0,b0);
  for i:=1 to a0 do begin
    readln(f1,b[i,1],b[i,2]);
    a[b[i,1],b[i,2]]:=0;
  end;

  for i:=1 to a0 do kz(b[i,1],b[i,2]);

  assign(f2,'crusade.out');
  rewrite(f2);
  for i:=1 to b0 do begin
    readln(f1,x,y);
    writeln(f2,a[x,y]);
  end;
  close(f1);
  close(f2);
end.