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
Main idea is: if we have got the line, we can try to find a point on it using linear search. If the line is not good enough, we can move it using binary search.
A
. Sort them for B
and C
too.A
to be all the points.A
. These 2 points define subrange for 'A'. Get some line AD
lying between these points.B
and AD
(starting from BA
). Stop when n
points found. Select subrange of directions from B
to points n
and next after n
(if there is no point after n
, use BC
). If less than n
points can be found, set current range for vertex A
to be the left half of the current range and go to step 3.C
.A
, B
, C
intersect, choose any point from there and finish. Otherwise, if A&B
is closer to A
, set current range for vertex A
to be the right half of the current range and go to step 3. Otherwise set current range for vertex A
to be the left half of the current range and go to step 3.Complexity: sorting O(n * log n)
, search O(n * log n)
. (Combination of binary and linear search).