记录编号 |
7629 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
zpl123 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.598 s |
提交时间 |
2008-11-10 20:49:43 |
内存使用 |
4.41 MiB |
显示代码纯文本
program crusade;
const
xx:array[1..4] of longint=(-1,1,0,0);
yy:array[1..4] of longint=(0,0,1,-1);
max=500;
type
posi=record
x,y:longint;
end;
var
f,f1:array[0..max+1,0..max+1] of boolean;
d:array[1..max,1..max] of longint;
c:array[1..max*max] of longint;
l:array[1..max*max+8] of posi;
n,m,a,b,h,t,t1,ans,tot:longint;
procedure init;
var
i,j,x1,y1:longint;
begin
assign(input,'crusade.in');
reset(input);
assign(output,'crusade.out');
rewrite(output);
fillchar(f,sizeof(f),false);
fillchar(f1,sizeof(f1),false);
readln(n,m,a,b);
for i:=1 to a do
begin
readln(x1,y1);
f[x1,y1]:=true;
l[i].x:=x1;
l[i].y:=y1;
end;
for i:=1 to b do
begin
readln(x1,y1);
f1[x1,y1]:=true;
d[x1,y1]:=i;
end;
h:=1; t:=a; tot:=0; ans:=0;
end;
procedure bfs;
var
i,j:longint;
begin
t1:=t;
for i:=h to t do
begin
if f1[l[i].x,l[i].y] then
begin
inc(tot);
c[d[l[i].x,l[i].y]]:=ans;
end;
for j:=1 to 4 do
if (l[i].x+xx[j]>=1)and(l[i].x+xx[j]<=n)and(l[i].y+yy[j]>=1)and(l[i].y+yy[j]<=m)
and(f[(l[i].x+xx[j]),(l[i].y+yy[j])]=false)
then
begin
f[(l[i].x+xx[j]),(l[i].y+yy[j])]:=true;
inc(t1);
l[t1].x:=l[i].x+xx[j];
l[t1].y:=l[i].y+yy[j];
end;{then}
end;
end;
procedure main;
begin
while tot<b do
begin
bfs;
inc(ans);
h:=t+1;
t:=t1;
end;
end;
procedure print;
var
i:longint;
begin
for i:=1 to b do writeln(c[i]);
close(input);
close(output);
end;
begin
init;
main;
print;
end.