记录编号 |
7542 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
francis |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.529 s |
提交时间 |
2008-11-10 17:00:39 |
内存使用 |
6.00 MiB |
显示代码纯文本
program crusade;
const
fin='crusade.in';
fou='crusade.out';
g:array[1..4,1..2]of longint=((-1,0),(0,1),(1,0),(0,-1));
var
f,a:array[1..501,1..501]of longint;
d,c:array[1..260000,1..2]of longint;
deep,x,y,p,n,m,n1,n2,i,j:longint;
f1,f2:text;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
read(f1,n,m,n1,n2);
for i:=1 to n do
for j:=1 to m do
f[i,j]:=-1;
for i:=1 to n1 do
begin
read(f1,d[i,1],d[i,2]);
f[d[i,1],d[i,2]]:=0;
end;
for i:=1 to n2 do
read(f1,c[i,1],c[i,2]);
p:=n1;
end;
procedure bfs(x,y:longint);
var
xx,yy:longint;
begin
inc(deep);
for i:=x to y do
for j:=1 to 4 do
begin
xx:=d[i,1]+g[j,1]; yy:=d[i,2]+g[j,2];
if (xx>0)and(xx<=n)and(yy>0)and(yy<=m)and(f[xx,yy]=-1) then
begin
f[xx,yy]:=deep;
inc(p);
d[p,1]:=xx; d[p,2]:=yy;
end;
end;
if p>=y+1 then bfs(y+1,p);
end;
procedure print;
begin
for i:=1 to n2 do
writeln(f2,f[c[i,1],c[i,2]]);
close(f1); close(f2);
end;
begin
init;
bfs(1,n1);
print;
end.