0

I have been trying to answer this question for months now but I am still stuck.

The question requires me to write a program to output YES or NO to whether the given set has a line that can divide it.

I am looking for a possible algorithm to determine the answer, I want to interpret it into code once I have a firm grasp on the answer.

Given an even length set of Circles on a 2D plane that are guaranteed not to touch. determine if it is possible to draw a line through the set dividing it exactly in two without intersecting any circle.

  • Circle Radius is greater than zero
  • No Circle touches or contains one another
  • A set of length 2 is always possible
  • every Circle can be unique in size

Input Format:

N - number of circles in set
x y r - N lines of: x coordinate, y coordinate, radius
Input repeats until EOF

Output YES or NO for each test case

Example input:

4
0 0 20
0 40 20
0 30 10
40 -30 10
4
0 0 20
0 40 20
20 40 20
20 -40 20

Output:

YES
NO

Edit: My attempts to solve

First attempt was to find all lines that could solve this problem if every circle were zero radius points to give me a set of possible solutions to the problem.

Link to a Dividing a plane of points into two equal halves

Afterwards I would return the radii back then iterate through each possible solution.

This algorithm was extremely slow (I did'nt bother to calculate the O time since the required algorithm was required to run in a reasonable time frame of a second)


My Second attempt was to project these circles onto the y and x axis and rotate the set until there existed a section of the x or y axis without a "shadow" of any circle while splitting the sets into two.

This method would only require a maximum rotation of 1/2pi radians to determine the answer but attempts to program were complex and slow.


I cannot find the question anywhere online as it was presented on paper last year created by a professor at my university.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
Caleb
  • 56
  • 7
  • And have you tried anything? O(n^3) algorithm is not hard. – MBo Apr 25 '18 at 17:32
  • @Caleb, you can add source of question(like project Euler, spoj etc), if some had solved that, they can help you. – dkb Apr 25 '18 at 18:40
  • @Prune - I have updated the question to reflect the absence of my work – Caleb Apr 26 '18 at 14:58
  • @dkb, This question was written and given by a professor so there are no online records of this question that I could find. I know it has been answered by someone else but I am unable to get their name/contact them. – Caleb Apr 26 '18 at 15:00
  • @MBo, I have edited the question with a few attempts – Caleb Apr 26 '18 at 15:05

1 Answers1

1

Simple algorithm with cubic complexity:

Find common tangents for all circle pairs. There are 4*n*(n-1)/2 ~ n^2 tangents.

For every tangent check whether it intersects all circles. n*n^2=n^3 operations


I think that algorithms with better complexity might exist (based on tangent direction sorting)

MBo
  • 77,366
  • 5
  • 53
  • 86