Description

给两个多边形,问否在平移旋转不翻转不重叠的情况下拼成一个凸多边形。

Input

每组第一行一个数N表示第一个多边形的顶点数,下接N行按顺序(逆/顺时针)给出顶点坐标,再下一行给一个数M表示第二个多边形的顶点数,下接M行按顺序给出顶点坐标。

Output

对于每组数据,输出一行0/1,1表示能,0表示不能。

Sample Input

4
0 0
0 1
1 1
1 0
4
0 0
0 1
1 1
1 0
4
0 0
0 1
1 1
1 0
4
0 0
0 1
1 1
1 0

Sample Output

1
1

HINT

对于100%的数据,N<=1000,M<=1000,顶点坐标为实数,标程精度1e-8

题解:

平面计算几何题。每次枚举相拼的两条边,在按顺序扫过两个多边形对应的变,检查是否是无缝屏接,拼好后是否是凸多边形。

注意给点的顺序不一定都是逆时针的,先按照给点的顺序扫过每一条边,记录下角度的偏转情况。若最终偏转为-2π,则为顺时针;若为2π,则为逆时针。

通过倒着排序给出的点,使两个多边形都变成是逆时针的,就可以正常做了。

代码:

 var
i,j,k,l,n,m:longint;
a,b:array[-..,..]of extended;
tt:array[..]of extended;
e:extended;
function dis(x,y,xx,yy:extended):extended;
begin
exit(sqrt(sqr(x-xx)+sqr(y-yy)));
end;
function xj2(x,y:extended):extended;
var i,j,k,l:longint;
begin
if(abs(x)<0.0000001)and(y>)then exit(pi/);
if(abs(x)<0.0000001)and(y<)then exit(*pi/);
if(abs(y)<0.0000001)and(x>)then exit();
if(abs(y)<0.0000001)and(x<)then exit(pi);
if(x>)and(y>)then exit(arctan(y/x));
if(x>)and(y<)then exit(*pi-arctan(-y/x));
if(x<)and(y>)then exit(pi/+arctan(-x/y));
if(x<)and(y<)then exit(pi+arctan(y/x));
end;
function xj(x,y,xx,yy,xxx,yyy:extended):extended;
var z1,z2:extended;
begin
z1:=xj2(x-xx,y-yy);
z2:=xj2(xxx-xx,yyy-yy);
while z2>0.0000001+z1 do z2:=z2-*pi;
exit(z1-z2);
end;
function ss:longint;
var i,j,ii,jj,k,l:longint;
z1,z2,z3:extended;
begin
for i:= to n do
for j:= to m do
if abs(dis(a[i-,],a[i-,],a[i,],a[i,])
-dis(b[j+,],b[j+,],b[j,],b[j,]))<0.0000001 then
begin
z1:=xj(a[i-,],a[i-,],a[i-,],a[i-,],a[i,],a[i,]);
z2:=xj(b[j+,],b[j+,],b[j+,],b[j+,],b[j,],b[j,]);
while z2>0.0000001+z1 do z2:=z2-*pi;
if z1-z2>pi+0.0000001 then continue;
ii:=i+; jj:=j-; l:=;
while true do
begin
z1:=xj(a[ii-,],a[ii-,],a[ii-,],a[ii-,],a[ii,],a[ii,]);
z2:=xj(b[jj+,],b[jj+,],b[jj+,],b[jj+,],b[jj,],b[jj,]);
while z2>0.0000001+z1 do z2:=z2-*pi;
if z1-z2<0.0000001 then
begin
if abs(dis(a[ii-,],a[ii-,],a[ii,],a[ii,])
-dis(b[jj+,],b[jj+,],b[jj,],b[jj,]))<0.0000001 then
begin inc(ii); dec(jj); end else begin l:=; break; end;
continue;
end;
if z1-z2<pi-0.0000001 then
begin l:=; break; end;
break;
end;
if l= then
begin
for k:=ii to i+n- do
if xj(a[k-,],a[k-,],a[k,],a[k,],a[k+,],a[k+,])>pi+0.0000001
then begin l:=; break; end;
for k:=jj downto j-m+ do
if xj(b[k+,],b[k+,],b[k,],b[k,],b[k-,],b[k-,])<pi-0.0000001
then begin l:=; break; end;
if l= then exit();
end;
end;
exit();
end;
begin
while not eof do
begin
readln(n);
for i:= to n do readln(a[i,],a[i,]);
a[n+]:=a[]; a[]:=a[n]; e:=;
for i:= to n do
e:=e+xj(a[i-,],a[i-,],a[i,],a[i,],a[i+,],a[i+,])-pi;
if e> then
begin
for i:= to n div do begin tt:=a[i]; a[i]:=a[n-i+]; a[n-i+]:=tt; end;
end;
for i:= to n do a[i-n]:=a[i];
for i:= to n do a[i+n]:=a[i];
readln(m);
for i:= to m do readln(b[i,],b[i,]);
b[m+]:=b[]; b[]:=b[m]; e:=;
for i:= to m do
e:=e+xj(b[i-,],b[i-,],b[i,],b[i,],b[i+,],b[i+,])-pi;
if e> then
begin
for i:= to m div do begin tt:=b[i]; b[i]:=b[m-i+]; b[m-i+]:=tt; end;
end;
for i:= to m do b[i-m]:=b[i];
for i:= to m do b[i+m]:=b[i];
writeln(ss);
end;
end.
05-06 01:45