比赛 NOIP2008集训模拟1 评测结果 ATAAAAATTA
题目名称 血色叛徒 最终得分 70
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-10 09:20:03
显示代码纯文本
program crusade;
type
shuzu=array[0..500,0..500] of longint;
shuzu1=array[1..250000,1..2] of longint;
shuzu2=array[1..500,1..500] of longint;
var
minf:shuzu2;
s,f:shuzu;
x,y:shuzu1;
a,b,i,j,k,m,n:longint;
function min(x,y:longint):longint;
begin
if x>=y then min:=y
        else min:=x;
        end;
begin
assign(input,'crusade.in');reset(input);
assign(output,'crusade.out');rewrite(output);
readln(n,m,a,b);
for i:=1 to n do
 for j:=1 to m do
 s[i,j]:=1;
 for i:=1 to n do
  for j:=1 to m do
  minf[i,j]:=maxlongint;
for i:=1 to a do
begin
readln(x[i,1],x[i,2]);
s[x[i,1],x[i,2]]:=0;
end;
for i:=1 to b do
readln(y[i,1],y[i,2]);
for k:=1 to a do
begin
fillchar(f,sizeof(f),0);
 f[x[k,1],x[k,2]]:=0;
 for i:=x[k,1]+1 to n do
  f[i,x[k,2]]:=f[i-1,x[k,2]]+1;
 for i:=x[k,1]-1 downto 1 do
  f[i,x[k,2]]:=f[i+1,x[k,2]]+1;
 for i:=x[k,2]+1 to m do
  f[x[k,1],i]:=f[x[k,1],i-1]+1;
 for i:=x[k,2]-1 downto 1 do
  f[x[k,1],i]:=f[x[k,1],i+1]+1;
  for i:=x[k,1]+1 to n do
   for j:=x[k,2]+1 to m do
   f[i,j]:=min(f[i-1,j]+s[i,j],f[i,j-1]+s[i,j]);
  for i:=x[k,1]-1 downto 1 do
   for j:=x[k,2]-1 downto 1 do
   f[i,j]:=min(f[i+1,j]+s[i,j],f[i,j+1]+s[i,j]);
  for i:=x[k,1]+1 to n do
   for j:=x[k,2]-1 downto 1 do
   f[i,j]:=min(f[i,j+1]+s[i,j],f[i-1,j]+s[i,j]);
  for i:=x[k,1]-1 downto 1 do
   for j:=x[k,2]+1 to m do
   f[i,j]:=min(f[i,j-1]+s[i,j],f[i+1,j]+s[i,j]);
  for i:=1 to b do
  if minf[y[i,1],y[i,2]]>f[y[i,1],y[i,2]] then minf[y[i,1],y[i,2]]:=f[y[i,1],y[i,2]];
end;
for i:=1 to b do
 writeln(minf[y[i,1],y[i,2]]);
  close(output);
  end.