Pagini recente » Cod sursa (job #3153591) | Cod sursa (job #1772840) | Cod sursa (job #393468) | Cod sursa (job #1444138) | Cod sursa (job #253845)
Cod sursa(job #253845)
program expresii;
var f,g:text;
i,m,n,x,y,r,j,nr:longint;
a,b:array[1..500] of longint;
mat:array[-300..300,-300..300] of longint;
begin
assign(f,'grendizer.in');
assign(g,'grendizer.out');
rewrite(g);
reset(f);
readln(f,n,m);
if n<501 then
begin
for i:=1 to n do
readln(f,a[i],b[i]);
for j:=1 to m do
begin
readln(f,x,y,r);
nr:=0;
for i:=1 to n do
if abs(x-a[i])+abs(y-b[i])=r then nr:=nr+1;
writeln(g,nr)
end;
end
else begin
for i:=1 to n do
begin
readln(x,y);
mat[x,y]:=mat[x,y]+1;
end;
for j:=1 to m do
begin
readln(f,x,y,r);
nr:=0;
if (x-r>=-300)then nr:=nr+mat[x-r,y];
if x+r<=300 then nr:=nr+mat[x+r,y];
for i:=x-r+1 to x do
begin
if (y-x+r+i>=-300)and(y-x+r+i<=300) then
nr:=nr+mat[i,y-x+r+i];
if (y+x-r-i>=-300)and(y+x-r-i<=300)then nr:=nr+mat[i,y+x-r-i];
end;
for i:=x+1 to x+r-1 do
begin
if (y-r+i-x>=-300)and(y-r+i-x<=300) then
nr:=nr+mat[i,y-r+i-x];
if (y+r-i+x>=-300)and(y+r-i+x<=300) then nr:=nr+mat[i,y+r-i+x];
end;
writeln(g,nr)
end;
end;
close(f);
close(g);
end.