Cod sursa(job #253868)

Utilizator albuaAlbu Alexandru albua Data 6 februarie 2009 13:06:51
Problema Grendizer Scor 10
Compilator fpc Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 1 Marime 1.21 kb
program grendizer;

var
  f,g:TEXT;
  n,m,x,y,i,x1,y1,x2,y2:longint;
  r,st,dr,temp,contor:longint;
  a:array[-2000..2000,-2000..2000]of integer;

begin
  assign(f,'grendizer.in');   reset(f);
  assign(g,'grendizer.out');  rewrite(g);
  readln(f,n,m);
  for i:=1 to n do
    begin
      readln(f,x,y);
      a[x][y]:=1;
    end;
  for i:=1 to m do
    begin
      contor:=0;
      readln(f,x1,y1,r);
      if(r>1200)then
        begin
          writeln(g,0);
          continue;
        end;
      st:=x1-r;
      dr:=x1+r;
      if(st>dr)then
        begin
          temp:=st;
          st:=dr;
          dr:=temp;
        end;
      if(st<-300)then st:=-300;
      if(dr>300)then dr:=300;
      for x2:=st to dr do
        begin
         temp:=r-abs(x1-x2);
         if(temp>=0)then
           begin
             {cazul unu y1-y2 = temp }
             y2:=y1-temp;
             if(a[x2][y2]=1)then contor:=contor+1;
             {cazul doi -y1+y2 = temp }
             y2:=temp+y1;
             if(a[x2][y2]=1)then
               if(temp+y1)<>(y1-temp)then
                 contor:=contor+1;
           end;
        end;
      writeln(g,contor);
    end;
  close(f);  close(g);
end.