比赛 |
NOIP2008集训模拟1 |
评测结果 |
ATWWWWTTTT |
题目名称 |
血色叛徒 |
最终得分 |
10 |
用户昵称 |
bing |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-10 09:42:12 |
显示代码纯文本
program bing;
const
max=500;
mm:array[1..4] of integer=(-1,0,0,1);
nn:array[1..4] of integer=(0,-1,1,0);
var
f1,f2:text;
n,m,a,b:integer;
map:array[1..max,1..max] of longint;
procedure jisuan(x,y:integer);
type
zuo=record
n:integer;
m:integer;
end;
var
i,j,k,dn,mt,nt:longint;
d:array[1..250000] of zuo;
begin
for i:=1 to n*m do
begin d[i].n:=0;d[i].m:=0;end;
dn:=1;d[1].n:=x;d[1].m:=y;
map[x,y]:=0;
k:=1;
repeat
for i:=k to dn do
begin
for j:=1 to 4 do
if (d[i].n+nn[j]>0)and(d[i].n+nn[j]<=n)and(d[i].m+mm[j]>0)and(d[i].m+mm[j]<=m)
then begin
nt:=d[i].n+nn[j];mt:=d[i].m+mm[j];
if map[d[i].n,d[i].m]+1<map[nt,mt] then
map[nt,mt]:=map[d[i].n,d[i].m]+1;
inc(dn);d[dn].n:=nt;d[dn].m:=mt;
end;
end;
k:=i+1;
until dn>=m*n;
end;
procedure init;
var
i,j,x,y:longint;
begin
assign(f1,'crusade.in');reset(f1);
assign(f2,'crusade.out');rewrite(F2);
readln(f1,n,m,a,b);
for i:=1 to n do
for J:=1 to m do map[i,j]:=250000;
for i:=1 to a do
begin
readln(F1,x,y);
jisuan(x,y);
end;
end;
procedure put;
var
i,j,x,y:longint;
begin
for i:=1 to b do
begin
readln(f1,x,y);
writeln(f2,map[x,y]);
end;
close(f1);close(f2);
end;
begin
init;
put;
end.