比赛 |
NOIP2008集训模拟1 |
评测结果 |
ATAATTTTTT |
题目名称 |
血色叛徒 |
最终得分 |
30 |
用户昵称 |
zxc111 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 11:25:12 |
显示代码纯文本
program ooo;
var
i,j,k,n,m,g,h:longint;
x,y,x1,y1:array[1..250000] of longint;
a:array[0..501,0..501] of longint;
f:array[0..501,0..501] of boolean;
t:text;
procedure oo(l,r:longint);
var
i,j,k:longint;
begin
f[l,r]:=true;
if (a[l+1,r]>a[l,r]+1)and(l+1<=n)and(f[l+1,r]=false) then begin a[l+1,r]:=a[l,r]+1;oo(l+1,r);end;
if (a[l-1,r]>a[l,r]+1)and(l>1)and(f[l-1,r]=false) then begin a[l-1,r]:=a[l,r]+1;oo(l-1,r);end;
if (a[l,r+1]>a[l,r]+1)and(r+1<=m)and(f[l,r+1]=false) then begin a[l,r+1]:=a[l,r]+1;oo(l,r+1);end;
if (a[l,r-1]>a[l,r]+1)and(r>1)and(f[l,r-1]=false) then begin a[l,r-1]:=a[l,r]+1;oo(l,r-1);end;
f[l,r]:=false;
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;
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
begin
fillchar(f,sizeof(f),false);
f[x1[i],y1[i]]:=true;
a[x1[i],y1[i]]:=0;
oo(x1[i],y1[i]);
f[x1[i],y1[i]]:=false;
end;
assign(t,'crusade.out');
rewrite(t);
for i:=1 to h do
writeln(t,a[x[i],y[i]]);
close(t);
end.