#P12144. Escape the Minefield
Escape the Minefield
Escape the Minefield
Blue is playing an escape game in the first quadrant of the Cartesian plane, where n mines are buried. The i-th mine is located at \((x_i,y_i)\) and has a trigger range defined by the circle centered at \((x_i,y_i)\) with radius \(r_i\). If Blue ever enters the interior of any of these circles, the mine will trigger and the game is lost.
Blue starts at the origin \((0,0)\) and, in order to escape, must choose a direction (in the first quadrant) along which he proceeds indefinitely. His success depends on whether his chosen ray avoids all the mines.
If Blue chooses a direction uniformly at random in the interval \([0, \frac{\pi}{2}]\) (where \(0^\circ\) points along the positive \(x\)-axis and \(90^\circ\) along the positive \(y\)-axis), what is the probability that he escapes all the mines?
Hint: For each mine, if its center is \((x,y)\) with \(d=\sqrt{x^2+y^2}\) and \(d>r\), then the ray originating from the origin will hit the mine if its angle \(\theta\) satisfies
\[ |\theta-\alpha|\leq\arcsin\frac{r}{d}, \quad \text{where}\; \alpha=\arctan\frac{y}{x}. \]If for any mine \(d\leq r\) then the mine's circle covers the origin and escape is impossible. Otherwise, compute the unsafe angle intervals from each mine, merge the overlapping intervals, and then determine the total safe angular measure. The escape probability is the safe measure divided by \(\frac{\pi}{2}\).
inputFormat
The first line contains a single integer \(n\) (the number of mines). Each of the following \(n\) lines contains three real numbers \(x\), \(y\), and \(r\), representing the coordinates of a mine and its trigger radius. It is guaranteed that \(x \ge 0\), \(y \ge 0\) (mines are in the first quadrant).
outputFormat
Output a single real number representing the probability of escaping safely. Your answer is considered correct if its absolute or relative error does not exceed \(10^{-6}\).
sample
1
2 2 1
0.539000