记录编号 |
7515 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
苏轼 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.534 s |
提交时间 |
2008-11-10 16:36:16 |
内存使用 |
2.50 MiB |
显示代码纯文本
program cch(input,output);
const
xx:array[1..4] of integer=(-1,0,1,0);
yy:array[1..4] of integer=(0,1,0,-1);
type
sz=record
x:integer;
y:integer;
k:integer;
end;
var
x,y,i,j,s,c,n,m,x1,y1,head,tail,k:longint;
a:array[1..250000] of sz;
f:array[1..500,1..500] of longint;
begin
assign(input,'crusade.in');
assign(output,'crusade.out');
reset(input);
rewrite(output);
readln(n,m,s,c);
for i:=1 to n do
for j:=1 to m do f[i,j]:=-1;
for i:=1 to s do
begin
readln(x,y);
a[i].x:=x; a[i].y:=y; a[i].k:=0;
f[x,y]:=0;
end;
head:=1; tail:=s;
repeat
for i:=1 to 4 do
begin
x1:=a[head].x+xx[i];
y1:=a[head].y+yy[i];
k:=a[head].k+1;
if (x1>=1)and(x1<=n)and(y1>=1)and(y1<=n) then
if f[x1,y1]=-1 then
begin
inc(tail);
a[tail].x:=x1; a[tail].y:=y1;
a[tail].k:=k;
f[x1,y1]:=k;
end;
end;
inc(head);
until head>tail;
for i:=1 to c do
begin
readln(x1,y1);
writeln(f[x1,y1]);
end;
close(input);
close(output);
end.