记录编号 7409 评测结果 AAAAAAAAAA
题目名称 [BYVoid S1] 血色叛徒 最终得分 100
用户昵称 Gravatarname:弓虽 是否通过 通过
代码语言 Pascal 运行时间 0.482 s
提交时间 2008-11-10 11:46:08 内存使用 7.05 MiB
显示代码纯文本
program crusade(input,output);
type
 rec=record
  x,y:longint;
  end;
 var
  i,j,k:longint;
  map:array [1..501,1..501] of longint;
  pan:array[1..501,1..501] of boolean;
  n,m,a,b,temp:longint;
  head,tail:longint;
  line,aa,bb:array [1..251000] of rec;

procedure find;

begin

 while head<tail do
  begin

   inc(head);

    if line[head].x-1>0 then begin
    if pan[line[head].x-1,line[head].y]=false
     then
      begin
       map[line[head].x-1,line[head].y]:=map[line[head].x,line[head].y]+1;
       pan[line[head].x-1,line[head].y]:=true;
       inc(tail);
       line[tail].y:=line[head].y;
       line[tail].x:=line[head].x-1;
      end;
     end;

     if line[head].y-1>0 then begin
      if pan[line[head].x,line[head].y-1]=false then
       begin
        map[line[head].x,line[head].y-1]:=map[line[head].x,line[head].y]+1;
        pan[line[head].x,line[head].y-1]:=true;
        inc(tail);
       line[tail].y:=line[head].y-1;
       line[tail].x:=line[head].x;
       end;
      end;
    if line[head].x+1<=n then
     begin
      if pan[line[head].x+1,line[head].y]=false then begin
       map[line[head].x+1,line[head].y]:=map[line[head].x,line[head].y]+1;
       pan[line[head].x+1,line[head].y]:=true;
      inc(tail);
      line[tail].y:=line[head].y;
      line[tail].x:=line[head].x+1;
      end;
     end;

    if line[head].y+1<=m then
     begin
      if pan[line[head].x,line[head].y+1]=false then begin
       map[line[head].x,line[head].y+1]:=map[line[head].x,line[head].y]+1;
       pan[line[head].x,line[head].y+1]:=true;
      inc(tail);
      line[tail].y:=line[head].y+1;
      line[tail].x:=line[head].x;
      end;
     end;
   end;
   end;


begin
 assign(input,'crusade.in');
 assign(output,'crusade.out');
 reset(input);
 rewrite(output);
 readln(n,m,a,b);

  fillchar(map,sizeof(map),0);
  fillchar(pan,sizeof(pan),false);

  for i:=1 to a do
   begin
    readln(aa[i].x,aa[i].y);
    pan[aa[i].x,aa[i].y]:=true;
   end;
  for i:=1 to b do
   readln(bb[i].x,bb[i].y);
   head:=0;
   tail:=a;
    for i:=1 to a do
     line[i]:=aa[i];
   find;
   for i:=1 to b do
    writeln(map[bb[i].x,bb[i].y]);
  close(input);
  close(output);
end.