This solution uses an "Exact" closed form solution.
Basic problem summary: calculate the probability of hitting a fly with a tennis racket.
CodeJam's Detailed statement: Code Jam 2008 Qualifying Round P3
The basic idea is the following:
- Divided the Tennis racket into 4 symmetric quadrants
- Calculate the area where the fly would be able to safely fly through
- Calculate the total Area
- Solution 1-safeArea/totalArea is the solution. format and maintain 6 sig figs.
Or In Code Calculate the Area of a Chord:
The North-East Case:
$$Area = gap^{2} - {1 \over 2} (xTwo - X_{RIM \space yTwo} ) * (yTwo - X_{RIM \space xTwo}) + ChordArea (X_{RIM \space yTwo},X_{RIM \space xTwo})$$,
West East Case:
$$ Area = gap*(yOne - RIM_{y \space xTwo}) + {{1 \over 2} (RIM_{y \space xOne} - RIM_{y \space xTwo})} + ChordArea (X_{RIM \space xTwo},X_{RIM \space xOne})$$
OR IN CODE In Code Area Calc for West-East Case:
For The North South And West South Cases: the code with picture is self explanatory, see the code at the bottom of the blog or on Git HUB