Forest
Time limit1sMemory limit128 MB
Given non-overlapping circles, find the farthest one visible from the origin along some segment that touches no other circle, and report its closest-point distance.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Implementation, Math
- Solved
- No attempts yet
Problem
Bruce Force is standing in the forest. He wonders which tree trunk is the farthest away that is not blocked from his view by other tree trunks.
Bruce has drawn a map of the trees in the forest. On the map his current position is the origin of a Cartesian coordinate system. Tree is drawn as a circle with center and radius . A tree trunk is considered visible if and only if there is a line segment on the map from the origin to some point on the border of that tree's circle such that the segment does not intersect or touch any other circle.
Input
The input contains several test cases. The first line of each test case contains an integer (), the number of trees on the map. Each of the following lines contains three integers , , (, ), where is the center of the circle representing tree trunk and is its radius.
No two circles intersect: for any two circles, the distance between their centers is strictly greater than the sum of their radii. No circle contains the origin.
The last test case is followed by a line containing a single .
Output
For each test case, print one line with the maximum Euclidean distance from the origin to a visible tree. The distance to a tree is measured to the point of that tree closest to the origin (that is, ), regardless of whether that particular point is itself visible.
Round the answer to exactly 3 digits after the decimal point.