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.