This was a problem in the 2010 Pacific ACM-ICPC contest. The gist of it is trying to find a way to partition a set of points inside a triangle into three subtriangles such that
Here's an O(n log n)
algorithm. Let's assume no degeneracy.
The high-level idea is, given a triangle PQR
,
P
C \
/ S\
R-----Q
we initially place the center point C
at P
. Slide C
toward R
until there are n
points inside the triangle CPQ
and one (S
) on the segment CQ
. Slide C
toward Q
until either triangle CRP
is no longer deficient (perturb C
and we're done) or CP
hits a point. In the latter case, slide C
away from P
until either triangle CRP
is no longer deficient (we're done) or CQ
hits a point, in which case we begin sliding C
toward Q
again.
Clearly the implementation cannot “slide” points, so for each triangle involving C
, for each vertex S
of that triangle other than C
, store the points inside the triangle in a binary search tree sorted by angle with S
. These structures suffice to implement this kinetic algorithm.
I assert without proof that this algorithm is correct.
As for the running time, each event is a point-line intersection and can be handled in time O(log n)
. The angles PC
and QC
and RC
are all monotonic, so each of O(1)
lines hits each point at most once.