记录编号 7591 评测结果 AAAAAAAAAA
题目名称 [BYVoid S1] 血色叛徒 最终得分 100
用户昵称 GravatarEnAsn 是否通过 通过
代码语言 Pascal 运行时间 0.514 s
提交时间 2008-11-10 18:40:47 内存使用 5.12 MiB
显示代码纯文本
program ex;
type
 data=record
  x,y:longint;
 end;
 ss=array[1..250000]of data;
 sz=array[0..500,0..500]of longint;
 zs=array[0..500,0..500]of boolean;
 sh=array[1..4]of data;
var
 a,b:ss;
 f:sz;
 c:zs;
 tim:sh;
 f1,f2:text;
 m,n,a1,b1:longint;
 i,j:longint;
 head,tail,wei,num:longint;
procedure init;
 var
  i:longint;
 begin
  assign(f1,'crusade.in');
  assign(f2,'crusade.out');
  reset(f1);
  rewrite(f2);
  readln(f1,n,m,a1,b1);
  for i:=1 to n do
   for j:=1 to m do
    f[i,j]:=-1;
  for i:=1 to a1 do
    readln(f1,a[i].x,a[i].y);
  for i:=1 to b1 do
   begin
    readln(f1,b[i].x,b[i].y);
    c[b[i].x,b[i].y]:=true;
   end;
  close(f1);
  for i:=1 to a1 do
   f[a[i].x,a[i].y]:=0;
  head:=1;wei:=a1;tail:=a1;
  tim[1].x:=0;tim[1].y:=1;
  tim[2].x:=1;tim[2].y:=0;
  tim[3].x:=0;tim[3].y:=-1;
  tim[4].x:=-1;tim[4].y:=0;
 end;
procedure try(head,tail:longint);
 var
  i,x,y:longint;
 begin
  for i:=head to tail do
    for j:=1 to 4 do
     begin
      x:=a[i].x+tim[j].x;
      y:=a[i].y+tim[j].y;
      if (f[x,y]=-1)and(x<=n)and(x>0)and(y>0)and(y<=m) then
       begin
        inc(wei);
        a[wei].x:=x;
        a[wei].y:=y;
        f[a[wei].x,a[wei].y]:=num;
       end;
     end;
 end;
procedure main;
 var
  i,j:longint;
 begin
  num:=0;
  while head<=tail do
   begin
    inc(num);
    try(head,tail);
    head:=tail+1;
    tail:=wei;
   end;
 end;
begin
 init;
 main;
 for i:=1 to b1 do
  writeln(f2,f[b[i].x,b[i].y]);
 {for i:=1 to n do
  begin
   for j:=1 to m do
    write(f2,f[i,j],' ');
   writeln(f2);
  end;}
 close(f2);
end.