najdeme potencionalni stred a overime (ke kazdemu bodu musi existovat protejsek)
{solve one situation - find the "center of gravity" and check whether every point has its counterpart} Function Solve (Var TwiceX, TwiceY: Integer) : Boolean; Var SX, SY: Integer; I: Integer; X: TPoint; Begin Solve := false; QuickSort (1, NumPts); SX := 0; SY := 0; For I := 1 to NumPts do Begin SX := SX + Pts[I].X; SY := SY + Pts[I].Y; End; If ((SX*2) mod NumPts = 0) and ((SY*2) mod NumPts = 0) then Begin SX := (SX*2) div NumPts; SY := (SY*2) div NumPts; Solve := true; For I := 1 to NumPts do Begin X := Pts[I]; X.X := SX - X.X; X.Y := SY - X.Y; If (BinSearch (X) = 0) then Solve := false; End; End; TwiceX := SX; TwiceY := SY; End;
pro uplnost quicksort... ;-)
{sorting function - not the best implementation but should be ok for us} Procedure QuickSort (L, R: Integer); Var LX, RX: Integer; Med, X: TPoint; Begin LX := L; RX := R; If (L < R) then Begin Med := Pts[(L+R) div 2]; If not Compare (Med, Pts[R]) then Med := Pts[R]; If (R-L > 15) then Med := Middle (Pts[L+3], Pts[R-3], Pts[(L+R) div 2 + 2]); While (L < R) do Begin While (L < R) and Compare (Pts[L], Med) do Inc (L); While (L < R) and not Compare (Pts[R], Med) do Dec (R); If (L < R) then Begin X := Pts[L]; Pts[L] := Pts[R]; Pts[R] := X; End; End; if Compare (Pts[L], Med) and (L < RX) then Inc (L) else Dec (R); QuickSort (LX, R); QuickSort (L, RX); End; End;