记录编号 |
7415 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
maxiem |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.645 s |
提交时间 |
2008-11-10 11:52:18 |
内存使用 |
3.92 MiB |
显示代码纯文本
program crusade;
const
d:array [1..4,1..2] of shortint=((0,-1),(0,1),(-1,0),(1,0));
max=500;
maxmn=250000;
type node=record
time,x,y:longint;
end;
var
i,newn,tx,ty,head,tail,a,b,n,m:longint;
table:array [1..max,1..max] of longint;
s:array [1..maxmn] of node;
begin
fillchar (table,sizeof(table),255);
fillchar (s,sizeof(s),255);
assign (input,'crusade.in');
reset (input);
assign (output,'crusade.out');
rewrite (output);
readln (n,m,a,b);
newn:=0;head:=1;tail:=1;
for i:=1 to a do begin
inc(newn);
readln (s[newn].x,s[newn].y);
end;
s[tail].time:=0;
for i:=head to head+newn-1 do begin
table[s[i].x,s[i].y]:=0;
s[i].time:=s[tail].time;
end;
while tail<=head do begin
head:=newn;newn:=head;
for i:=1 to 4 do begin
tx:=s[tail].x+d[i,1];ty:=s[tail].y+d[i,2];
if (tx>=1) and (tx<=n) and (ty>=1) and (ty<=m) then if (table[tx,ty]=-1) then begin
inc(newn);
s[newn].x:=tx;
s[newn].y:=ty;
s[newn].time:=s[tail].time+1;
table[tx,ty]:=s[newn].time;
end;
end;
inc(tail);
end;
for i:=1 to b do begin
readln (tx,ty);
writeln (table[tx,ty]);
end;
close (input);
close (output);
end.