记录编号 7488 评测结果 AAAAAAAAAA
题目名称 [BYVoid S1] 血色叛徒 最终得分 100
用户昵称 Gravatarbing 是否通过 通过
代码语言 Pascal 运行时间 0.631 s
提交时间 2008-11-10 16:23:17 内存使用 2.02 MiB
显示代码纯文本
program bing;
type
 zuo=record
 n:integer;
 m:integer;
end;
const
 max=500;
 mm:array[1..4] of integer=(-1,0,0,1);
 nn:array[1..4] of integer=(0,-1,1,0);
var
 f1,f2:text;
 n,m,a,b:longint;
 d:array[1..250000] of zuo;
 map:array[1..max,1..max] of longint;
procedure nb;
var
 i,j,k,dn,dnf,mt,nt:longint;
 jb:array[1..max,1..max] of boolean;
begin
 fillchar(jb,sizeof(jb),true);
 dn:=a;
 k:=1;
 for i:=k to dn do begin
 map[d[i].n,d[i].m]:=0;jb[d[i].n,d[i].m]:=false; end;
 repeat
 dnf:=dn;
 for i:=k to dnf do
 begin
  for j:=1 to 4 do
  if (d[i].n+nn[j]>0)and(d[i].n+nn[j]<=n)and(d[i].m+mm[j]>0)and(d[i].m+mm[j]<=m)
  and(jb[d[i].n+nn[j],d[i].m+mm[j]])then  begin
  nt:=d[i].n+nn[j];mt:=d[i].m+mm[j];
  if map[d[i].n,d[i].m]+1<map[nt,mt] then
  map[nt,mt]:=map[d[i].n,d[i].m]+1;
  jb[nt,mt]:=false;
  inc(dn);d[dn].n:=nt;d[dn].m:=mt;
  end;
 end;
 k:=i+1;
 until dn>=m*n;
end;
procedure init;
var
 i,j,x,y:longint;
begin
 assign(f1,'crusade.in');reset(f1);
 assign(f2,'crusade.out');rewrite(F2);
 readln(f1,n,m,a,b);
 for i:=1 to n do
 for J:=1 to m do map[i,j]:=250000;
 for i:=1 to a do
 begin
 readln(F1,x,y);
 d[i].n:=x;d[i].m:=y;
 end;
end;

procedure put;
var
 i,j,x,y:longint;
begin
 for i:=1 to b do
 begin
 readln(f1,x,y);
 writeln(f2,map[x,y]);
 end;
 close(f1);close(f2);
end;
begin
 init;
 nb;
 put;
end.