记录编号 |
7770 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
lc |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.532 s |
提交时间 |
2008-11-11 16:56:09 |
内存使用 |
6.80 MiB |
显示代码纯文本
program e1;
const
d:array[1..4,1..2] of integer=((1,0),(-1,0),(0,1),(0,-1));
maxn=500;
var
N,M,T1,T2:longint;
a,b:array[1..maxn*maxn+4] of record
x,y:longint;
end;
ans:array[1..maxn+4,1..maxn+4] of longint;
q:array[1..maxn*maxn+4] of record
x,y:longint;
end;
procedure init;
var
i:longint;
begin
readln(n,m,t1,t2);
for i:=1 to t1 do read(a[i].x,a[i].y);
for i:=1 to t2 do read(b[i].x,b[i].y);
end;
procedure main;
var
head,tail,x,y,xx,yy,i:longint;
begin
fillchar(ans,sizeof(ans),$FF);
head:=1; tail:=t1; for i:=1 to t1 do begin
q[i].x:=a[i].x;
q[i].y:=a[i].y;
ans[a[i].x,a[i].y]:=0;
end;
repeat
x:=q[head].x; y:=q[head].y;
for i:=1 to 4 do
begin
xx:=x+d[i,1]; yy:=y+d[i,2];
if (xx>=1) and (xx<=n) and (yy>=1) and (yy<=m)
then if ans[xx,yy]=-1
then
begin
inc(tail);
q[tail].x:=xx; q[tail].y:=yy;
ans[xx,yy]:=ans[x,y]+1;
end;
end;
inc(head);
until head>tail;
end;
procedure print;
var
i:longint;
begin
for i:=1 to t2 do
writeln(ans[b[i].x,b[i].y]);
end;
begin
assign(input,'crusade.in');
assign(output,'crusade.out');
reset(input); rewrite(output);
init;
main;
print;
close(input); close(output);
end.