记录编号 |
7500 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
王瑞祥K |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.528 s |
提交时间 |
2008-11-10 16:29:14 |
内存使用 |
2.97 MiB |
显示代码纯文本
program crusade(input,output);
type
point=record
x,y:integer;
end;
const
k:array[1..4]of point=((x:1;y:0),(x:0;y:1),(x:-1;y:0),(x:0;y:-1));
var
sou,goal:array[1..250000]of point;
ans:array[1..500,1..500]of longint;
m,n,a,b,dep:longint;
procedure ini;
var i,j:longint;
begin
assign(input,'crusade.in');assign(output,'crusade.out');
reset(input);rewrite(output);
readln(n,m,a,b);
for i:=1 to n do
for j:=1 to m do
ans[i,j]:=-1;
for i:=1 to a do begin readln(sou[i].x,sou[i].y);ans[sou[i].x,sou[i].y]:=0;end;
for i:=1 to b do readln(goal[i].x,goal[i].y);
dep:=0;
end;
procedure bfs(x,y:longint);
var i,j,xx,yy:longint;
begin
inc(dep);
for i:=x to y do
for j:=1 to 4 do begin
xx:=sou[i].x+k[j].x; yy:=sou[i].y+k[j].y;
if (xx>0)and(xx<=n)and(yy>0)and(yy<=m)and(ans[xx,yy]=-1)then begin
ans[xx,yy]:=dep;
inc(a);
sou[a].x:=xx; sou[a].y:=yy;
end;
end;
if a>=y+1 then bfs(y+1,a);
end;
procedure print;
var i:longint;
begin
for i:=1 to b do
writeln(ans[goal[i].x,goal[i].y]);
close(input);close(output);
end;
begin
ini;
bfs(1,a);
print;
end.