program DIVIDE; type TPoint=record X,Y:Real end; TLine=record Point1,Point2:TPoint end; TMulti=array of TLine; function PseudoScalar(const Line:TLine):Real; begin with Line do Result:=Point1.X*Point2.Y-Point1.Y*Point2.X end; function DX(const Line:TLine):Real; begin with Line do Result:=Point2.X-Point1.X end; function DY(const Line:TLine):Real; begin with Line do Result:=Point2.Y-Point1.Y end; function KL(const Line:TLine;var K,L:Real):Boolean; begin with Line do if Point1.X<>Point2.X then begin K:=DY(Line)/DX(Line); with Point1 do L:=Y-K*X; Result:=False end else Result:=True end; function IsInRange(const N:Real;R1,R2:Real):Boolean; var T:Real; begin if R1>R2 then begin T:=R1; R1:=R2; R2:=T end; Result:=(N>=R1)and(N<=R2) end; function IsInLine(const P:TPoint;const Line:TLine):Boolean; begin with Line,P do Result:=IsInRange(X,Point1.X,Point2.X) and IsInRange(Y,Point1.Y,Point2.Y) end; function Peret(const Line1,Line2:TLine;out P:TPoint):Boolean; var K1,L1,K2,L2:Real;V1,V2:Boolean; begin Result:=False; V1:=KL(Line1,K1,L1); V2:=KL(Line2,K2,L2); if V1 and V2 then Exit; with P do begin if V1 then begin X:=Line1.Point1.X; Y:=K2*X+L2 end else begin if V2 then X:=Line2.Point1.X else begin if K1=K2 then Exit; X:=(L2-L1)/(K1-K2); end; Y:=K1*X+L1 end; end; Result:=IsInLine(P,Line1) and IsInLine(P,Line2) end; procedure NewLine(const P1,P2:TPoint;out Line:TLine); begin with Line do begin Point1:=P1; Point2:=P2 end; end; procedure ReadPoint(out P:TPoint); begin with P do Read(X,Y) end; procedure ReadMulti(out M:TMulti); var i,n:integer; p:array of TPoint; begin readln(n); SetLength(p,n+1); for i:=0 to n-1 do ReadPoint(p[i]); p[n]:=p[0]; SetLength(m,n); for i:=0 to n-1 do NewLine(p[i],p[i+1],m[i]); SetLength(p,0) end; procedure WritePoint(const P:TPoint;const Plus:String=''); begin with P do Write(X:0:3,' ',Y:0:3); Write(Plus) end; var t,i,j:integer; P:array[1..2]of TPoint; F:array[1..2]of Boolean; m1,m2:TMulti; begin Assign(Input,'DIVIDE.DAT');Reset(Input); Assign(Output,'DIVIDE.SOL');Rewrite(Output); ReadMulti(m1); ReadMulti(m2); t:=1; for i:=0 to High(m1) do begin for j:=0 to High(m2) do begin F[t]:=Peret(m1[i],m2[j],P[t]); if F[t] then Inc(t); if t>2 then Break; end; if t>2 then Break end; SetLength(m1,0); SetLength(m2,0); WritePoint(P[1],' '); WritePoint(P[2],#13#10); Close(Input);Close(Output) end.