Triangle partitioning

后端 未结 4 574
说谎
说谎 2021-01-31 19:10

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

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 19:43

    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.

    enter image description here

    1. Sort the points based on the direction from vertex A. Sort them for B and C too.
    2. Set current range for vertex A to be all the points.
    3. Select 2 middle points from the range for vertex A. These 2 points define subrange for 'A'. Get some line AD lying between these points.
    4. Iterate for all the points lying between 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.
    5. Same as step 4, but for vertex C.
    6. If subranges 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).

提交回复
热议问题