Pagini recente » Cod sursa (job #696534) | Cod sursa (job #2877223) | Cod sursa (job #3233681) | Cod sursa (job #328536) | Cod sursa (job #197745)
Cod sursa(job #197745)
program gropi;
var f, g:text;
q,d, a, b, n, m, j, i, min, max, x1, x2, y1, y2, inc, c:longint;
ma:array[1..2,1..8000] of longint;
gasit:boolean;
begin
assign(f,'gropi.in'); reset(f);
assign(g,'gropi.out'); rewrite(g);
readln(f,c,n);
for i:=1 to 2 do
for j:=1 to c do
ma[i,j]:=1;
for i:=1 to n do
begin
readln(f,a,b);
ma[a,b]:=2;
end;
readln(f,m);
for i:=1 to m do
begin
readln(f,x1,y1,x2,y2);
d:=0;
if y1<y2 then
begin
min:=y1;
max:=y2;
inc:=x1;
q:=x2;
end
else
begin
min:=y2;
max:=y1;
inc:=x2;
q:=x1;
end;
gasit:=false;
j:=min;
while not gasit do
begin
d:=d+1;
if ma[inc,j+1]=2 then inc:=3-inc
else j:=j+1;
if j>max then gasit:=true;
end;
if inc<>q then d:=d+1;
writeln(g,d+1);
end;
close(f);
close(g);
end.