比赛 |
NOIP2008集训模拟1 |
评测结果 |
ATWWWWETTE |
题目名称 |
血色叛徒 |
最终得分 |
10 |
用户昵称 |
name:弓虽 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 11:24:25 |
显示代码纯文本
program crusade(input,output);
type
rec=record
x,y:longint;
end;
var
i,j,k:longint;
map:array [1..501,1..501] of longint;
pan:array[1..501,1..501] of boolean;
n,m,a,b,temp:longint;
head,tail:longint;
line,aa,bb:array [1..25100] of rec;
procedure find;
begin
while head<tail do
begin
inc(head);
if line[head].x-1>0 then begin
if pan[line[head].x-1,line[head].y]=false
then
begin
map[line[head].x-1,line[head].y]:=map[line[head].x,line[head].y]+1;
pan[line[head].x-1,line[head].y]:=true;
inc(tail);
line[tail].y:=line[head].y;
line[tail].x:=line[head].x-1;
end;
end;
if line[head].y-1>0 then begin
if pan[line[head].x,line[head].y-1]=false then
begin
map[line[head].x,line[head].y-1]:=map[line[head].x,line[head].y]+1;
pan[line[head].x,line[head].y-1]:=true;
inc(tail);
line[tail].y:=line[head].y-1;
line[tail].x:=line[head].x;
end;
end;
if line[head].x+1<=n then
begin
if pan[line[head].x+1,line[head].y]=false then begin
map[line[head].x+1,line[head].y]:=map[line[head].x,line[head].y]+1;
pan[line[head].x+1,line[head].y]:=true;
inc(tail);
line[tail].y:=line[head].y;
line[tail].x:=line[head].x+1;
end;
end;
if line[head].y+1<=m then
begin
if pan[line[head].x,line[head].y+1]=false then begin
map[line[head].x,line[head].y+1]:=map[line[head].x,line[head].y]+1;
pan[line[head].x,line[head].y+1]:=true;
inc(tail);
line[tail].y:=line[head].y+1;
line[tail].x:=line[head].x;
end;
end;
end;
end;
begin
assign(input,'crusade.in');
assign(output,'crusade.out');
reset(input);
rewrite(output);
readln(n,m,a,b);
fillchar(map,sizeof(map),0);
fillchar(pan,sizeof(pan),false);
for i:=1 to a do
begin
readln(aa[i].x,aa[i].y);
pan[aa[i].x,aa[i].y]:=true;
end;
for i:=1 to b do
readln(bb[i].x,bb[i].y);
head:=1;
tail:=a;
for i:=1 to a do
line[i]:=aa[i];
find;
for i:=1 to b do
writeln(map[bb[i].x,bb[i].y]);
close(input);
close(output);
end.