记录编号 7547 评测结果 AAAAAAAAAA
题目名称 [BYVoid S1] 血色叛徒 最终得分 100
用户昵称 Gravatarzxc111 是否通过 通过
代码语言 Pascal 运行时间 0.462 s
提交时间 2008-11-10 17:03:24 内存使用 62.39 MiB
显示代码纯文本
program ooo;
var
i,j,k,n,m,g,h:longint;
x,y,x1,y1:array[0..4000000] of longint;
a:array[0..510,0..510] of longint;
f:array[0..510,0..510] of boolean;
t:text;
procedure oo(l,r:longint);
var
i,j,k:longint;
begin

j:=r;
for i:=l to r do
 if (x1[i]<>0) then if (y1[i]<>0) then
 begin
  if a[x1[i],y1[i]]+1<a[x1[i]+1,y1[i]] then begin a[x1[i]+1,y1[i]]:=a[x1[i],y1[i]]+1;inc(j);x1[j]:=x1[i]+1;y1[j]:=y1[i];end;
  if a[x1[i],y1[i]]+1<a[x1[i]-1,y1[i]] then begin a[x1[i]-1,y1[i]]:=a[x1[i],y1[i]]+1;inc(j);x1[j]:=x1[i]-1;y1[j]:=y1[i];end;
  if a[x1[i],y1[i]]+1<a[x1[i],y1[i]+1] then begin a[x1[i],y1[i]+1]:=a[x1[i],y1[i]]+1;inc(j);x1[j]:=x1[i];y1[j]:=y1[i]+1;end;
  if a[x1[i],y1[i]]+1<a[x1[i],y1[i]-1] then begin a[x1[i],y1[i]-1]:=a[x1[i],y1[i]]+1;inc(j);x1[j]:=x1[i];y1[j]:=y1[i]-1;end;
 end;
 if j<r+1 then exit;
oo(r+1,j);
end;
begin
assign(t,'crusade.in');
reset(t);
readln(t,n,m,g,h);
for i:=0 to n+1 do
 for j:=0 to m+1 do
  a[i,j]:=maxlongint-1000;
for i:=1 to g do
readln(t,x1[i],y1[i]);
for i:=1 to h do
readln(t,x[i],y[i]);
close(t);
for i:=1 to g do
a[x1[i],y1[i]]:=0;
oo(1,g);
assign(t,'crusade.out');
rewrite(t);
for i:=1 to h do
writeln(t,a[x[i],y[i]]);
close(t);
end.