比赛 NOIP2008集训模拟1 评测结果 AEEEEEEEEE
题目名称 血色叛徒 最终得分 10
用户昵称 elysian 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-10 11:30:03
显示代码纯文本
program p_crusade;
const fin='crusade.in';fout='crusade.out';
     maxn=500;
     k:array[1..4,1..2]of integer=((-1,0),(1,0),(0,-1),(0,1));
type node=record
       x,y:integer;
       end;
var a:array[1..maxn,1..maxn]of boolean;
    b:array[1..maxn,1..maxn]of longint;
    p:array[0..1,1..maxn*maxn+5]of node;
    c:array[1..500]of node;
    l1,l2:array[0..1]of longint;
    f1,f2:text;
    n,m,a1,b1,i,j,lb,lp,now:longint;
procedure outout;
var i:longint;
begin
  for i:=1 to b1 do
    writeln(f2,0);
  close(f1);close(f2);
  halt;
end;
procedure init;
var i,j:longint;
begin
  assign(f1,fin);reset(f1);
  assign(f2,fout);rewrite(f2);
  read(f1,n,m,a1,b1);
  fillchar(a,sizeof(a),true);
  l2[0]:=a1;
  for i:=1 to a1 do
     with p[0,i] do
       begin read(f1,x,y);
             a[x,y]:=false;
       end;
  fillchar(b,sizeof(b),0);
  for i:=1 to b1 do
    with c[i] do
    begin
      read(f1,x,y);
      b[x,y]:=-1;
    end;
  lb:=0;
  for i:=1 to a1 do
    with p[0,i] do
     begin
      if (b[x,y]=-1) then inc(lb);
      b[x,y]:=0;
     end;
    if lb=b1 then outout;
end;
procedure print;
var i:longint;
begin
  for i:=1 to b1 do
    with c[i] do
      writeln(f2,b[x,y]);
{  for i:=1 to n do
    begin
      for j:=1 to m do
        write(b[i,j]:5);
      writeln;
    end;}
  close(f1);
  close(f2);
  halt;
end;
procedure doit;
var v,x1,y1:longint;
begin
  lp:=0;
  now:=0;l1[0]:=0;
  repeat
     l1[1-now]:=0;l2[1-now]:=0;
     inc(lp);
       repeat inc(l1[now]);
           for v:=1 to 4 do
             with p[now,l1[now]] do
                begin x1:=k[v,1]+x;y1:=k[v,2]+y;
                      if (a[x1,y1])and(x1>0)and(x1<=n)and(y1>0)and(y1<=m) then
                         begin inc(l2[1-now]);
                               with p[1-now,l2[1-now]] do
                                  begin x:=x1;y:=y1;
                                        if b[x,y]=-1 then
                                           begin inc(lb);
                                                 b[x,y]:=lp;a[x,y]:=false;
                                                 if lb=b1 then print;
                                           end;
                                        b[x,y]:=lp;
                                        a[x,y]:=false;
                                  end;
                         end;
                end;
       until l1[now]=l2[now];
     now:=1-now;
  until l2[now]=0;
end;
begin
  init;
  doit;
  print;
  close(f1);
  close(f2);
end.