显示代码纯文本
var
a,b,c,d,q:array[0..50005] of longint;
f,f1:array[-40005..40005] of longint;
vv:array[-40005..40005] of boolean;
n,ans1,ans2:longint;
procedure qsort(ll,rr:longint);
var i,j,x,y,t:longint;
begin
i:=ll;j:=rr;x:=a[(ll+rr)>>1];y:=b[(ll+rr)>>1];
repeat
while (b[i]<y) or ((b[i]=y)and(a[i]<x)) do inc(i);
while (b[j]>y) or ((b[j]=y)and(a[j]>x)) do dec(j);
if i<=j then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
inc(i);dec(j);
end;
until i>j;
if i<rr then qsort(i,rr);
if ll<j then qsort(ll,j);
end;
procedure sort(ll,rr:longint);
var i,j,x,y,t:longint;
begin
i:=ll;j:=rr;x:=c[(ll+rr)>>1];y:=d[(ll+rr)>>1];
repeat
while (d[i]<y) or ((d[i]=y)and (c[i]<x)) do inc(i);
while (d[j]>y) or ((d[j]=y)and (c[j]>x)) do dec(j);
if i<=j then
begin
t:=c[i];c[i]:=c[j];c[j]:=t;
t:=d[i];d[i]:=d[j];d[j]:=t;
inc(i);dec(j);
end;
until i>j;
if i<rr then sort(i,rr);
if ll<j then sort(ll,j);
end;
procedure init;
var i:longint;
begin
readln(n);
for i:=1 to n do
readln(a[i],b[i]);
for i:=1 to n do
readln(c[i],d[i]);
end;
function min(xx,yy:longint):longint;
begin
if xx<=yy then exit(xx);
exit(yy);
end;
function max(xx,yy:longint):longint;
begin
if xx<=yy then exit(yy);
exit(xx);
end;
function okone(i,j,k:longint):boolean;
var temp,temp1:int64;
begin
temp:=int64(a[j]-a[k])*int64(b[i]-b[j]);
temp1:=int64(a[i]-a[j])*int64(b[j]-b[k]);
if temp>temp1 then exit(true);
exit(false);
end;
function oktwo(i,j,k:longint):boolean;
var temp,temp1:int64;
begin
temp:=int64(c[j]-c[k])*int64(d[i]-d[j]);
temp1:=int64(c[i]-c[j])*int64(d[j]-d[k]);
if temp>temp1 then exit(true);
exit(false);
end;
procedure dofindone(j,k:longint);
var i,w:longint;
temp:real;
begin
if a[j]=a[k] then
begin
vv[a[j]]:=true;
f[a[j]]:=min(f[a[j]],b[j]);
f1[a[j]]:=max(f1[a[j]],b[j]);
f[a[j]]:=min(f[a[j]],b[k]);
f1[a[j]]:=max(f1[a[j]],b[k]);
exit;
end;
temp:=(b[k]-b[j])/(a[k]-a[j]);
for i:=a[j] to a[k] do
begin
vv[i]:=true;
w:=trunc((i-a[j])*temp+b[j]);
f[i]:=min(f[i],w);
f1[i]:=max(f1[i],w);
end;
for i:=a[k] to a[j] do
begin
vv[i]:=true;
w:=trunc((i-a[k])*temp+b[k]);
f[i]:=min(f[i],w);
f1[i]:=max(f1[i],w);
end;
end;
procedure dofindtwo(j,k:longint);
var i,w:longint;
temp:real;
begin
if c[j]=c[k] then
begin
vv[c[j]]:=true;
f[c[j]]:=min(f[c[j]],d[j]);
f1[c[j]]:=max(f1[c[j]],d[j]);
f[c[j]]:=min(f[c[j]],d[k]);
f1[c[j]]:=max(f1[c[j]],d[k]);
exit;
end;
temp:=(d[k]-d[j])/(c[k]-c[j]);
for i:=c[j] to c[k] do
begin
vv[i]:=true;
w:=trunc((i-c[j])*temp+d[j]);
f[i]:=min(f[i],w);
f1[i]:=max(f1[i],w);
end;
for i:=c[k] to c[j] do
begin
vv[i]:=true;
w:=trunc((i-c[k])*temp+d[k]);
f[i]:=min(f[i],w);
f1[i]:=max(f1[i],w);
end;
end;
procedure enterone;
var i,j,tail:longint;
begin
q[1]:=1;q[2]:=2; tail:=2;
for i:=3 to n do
begin
while (tail>1) and (okone(i,q[tail],q[tail-1])) do dec(tail);
inc(tail);q[tail]:=i;
end;
for i:=n-1 downto 1 do
begin
while (tail>1) and (okone(i,q[tail],q[tail-1])) do dec(tail);
inc(tail);q[tail]:=i;
end;
fillchar(f,sizeof(f),100);
fillchar(f1,sizeof(f1),130);
fillchar(vv,sizeof(vv),0);
for i:=2 to tail do
dofindone(q[i-1],q[i]);
ans1:=0;
for i:=1 to n do
if vv[c[i]] then
if (f[c[i]]<=d[i])and (d[i]<=f1[c[i]]) then inc(ans1);
end;
procedure entertwo;
var i,j,tail:longint;
begin
fillchar(q,sizeof(q),0);
q[1]:=1;q[2]:=2;tail:=2;
for i:=3 to n do
begin
while (tail>1) and (oktwo(i,q[tail],q[tail-1])) do dec(tail);
inc(tail);q[tail]:=i;
end;
for i:=n-1 downto 1 do
begin
while (tail>1) and (oktwo(i,q[tail],q[tail-1])) do dec(tail);
inc(tail);q[tail]:=i;
end;
fillchar(f,sizeof(f),100);
fillchar(f1,sizeof(f1),130);
fillchar(vv,sizeof(vv),0);
ans2:=0;
for i:=2 to tail do
dofindtwo(q[i-1],q[i]);
for i:=1 to n do
if vv[a[i]] then
if (f[a[i]]<=b[i]) and (f1[a[i]]>=b[i]) then inc(ans2);
end;
procedure main;
begin
qsort(1,n);
sort(1,n);
enterone;
entertwo;
writeln(ans1,' ',ans2);
end;
begin
assign(input,'curling.in');reset(input);
assign(output,'curling.out');rewrite(output);
init;main;
close(input);close(output);
end.