比赛 |
NOIP2008集训模拟1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
血色叛徒 |
最终得分 |
100 |
用户昵称 |
MayLava |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 10:58:33 |
显示代码纯文本
program MayLava;
type
rec=record
x,y:longint;
end;
var
map:array[1..500,1..500]of longint;
qe:array[1..250000] of rec;
p,q:array[1..250000]of rec;
m,n,a,b,e:longint;
procedure start;
var
f:text;
i,j:longint;
begin
assign(f,'crusade.in');
reset(f);
readln(f,n,m,a,b);
for i:=1 to n do
for j:=1 to m do
map[i,j]:=maxlongint;
for i:=1 to a do begin
readln(f,p[i].x,p[i].y);
map[p[i].x,p[i].y]:=0;
end;
for i:=1 to b do begin
readln(f,q[i].x,q[i].y);
end;
close(f);
end;
procedure print;
var
i:longint;
f:text;
begin
assign(f,'crusade.out');
rewrite(f);
for i:=1 to b do
writeln(f,map[q[i].x,q[i].y]);
close(f);
halt;
end;
procedure hunt(o:longint);
begin
with qe[o] do begin
if (x+1<=n) and (map[x+1,y]>map[x,y]+1) then begin map[x+1,y]:=map[x,y]+1; inc(e); qe[e].x:=x+1; qe[e].y:=y; end;
if (x-1>=1) and (map[x-1,y]>map[x,y]+1) then begin map[x-1,y]:=map[x,y]+1; inc(e); qe[e].x:=x-1; qe[e].y:=y; end;
if (y+1<=m) and (map[x,y+1]>map[x,y]+1) then begin map[x,y+1]:=map[x,y]+1; inc(e); qe[e].x:=x; qe[e].y:=y+1; end;
if (y-1>=1) and (map[x,y-1]>map[x,y]+1) then begin map[x,y-1]:=map[x,y]+1; inc(e); qe[e].x:=x; qe[e].y:=y-1; end;
end;
if o+1>e then print
else hunt(o+1);
end;
procedure main;
var
i:longint;
begin
for i:=1 to a do begin
qe[i].x:=p[i].x;
qe[i].y:=p[i].y;
end;
e:=a;
hunt(1);
end;
BEGIN
start;
main;
print;
END.