比赛 NOIP2008集训模拟1 评测结果 TEAEEWEETE
题目名称 血色叛徒 最终得分 10
用户昵称 书剑飘零 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-10 11:06:10
显示代码纯文本
program tz;
var
  a:array[0..500,0..500] of integer;
  b:array[1..10,1..2] of integer;
  long,x,y,a0,b0,n,m:integer;
  i,j:integer;
  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.