比赛 |
NOIP2008集训模拟1 |
评测结果 |
ATAATTTTTT |
题目名称 |
血色叛徒 |
最终得分 |
30 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 11:23:14 |
显示代码纯文本
program e1;
const
d:array[1..4,1..2] of integer=((0,1),(0,-1),(1,0),(-1,0));
maxn=500; maxm=500;
var
n,m,a,b:integer;
g:array[1..maxn,1..maxm] of integer;
ax,bx,ay,by:array[1..maxn*maxm] of integer;
procedure init;
var
i:integer;
begin
readln(n,m,a,b);
for i:=1 to a do read(ax[i],ay[i]);
for i:=1 to b do read(bx[i],by[i]);
end;
procedure fill(x,y:integer);
var
i,xx,yy:integer;
begin
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 (g[x,y]+1<g[xx,yy]) or (g[xx,yy]=-1)
then begin
g[xx,yy]:=g[x,y]+1;
fill(xx,yy);
end;
end;
end;
procedure main;
var
i:integer;
begin
fillchar(g,sizeof(g),$FF);
for i:=1 to a do
begin
g[ax[i],ay[i]]:=0;
fill(ax[i],ay[i]);
end;
for i:=1 to b do
writeln(g[bx[i],by[i]]);
end;
begin
assign(input,'crusade.in');
assign(output,'crusade.out');
reset(input); rewrite(output);
init;
main;
close(input); close(output);
end.