Compute the probability that a randomly placed fly disk touches a circular ring crossed by a grid of cylindrical strings, and print it to six decimals.
Hard8GeometryMathProbabilityImplementationNo attempts yetTime limit5sMemory limit512 MBWhat are your chances of hitting a fly with a tennis racquet?
Ignore the racquet's handle. Assume the racquet is a perfect ring with outer radius R and thickness t, so the inner radius of the ring is R−t.
The inside of the ring is covered with horizontal and vertical strings. Each string is a cylinder of radius r and lies along a chord of the ring, a straight line joining two points of the circle. Neighbouring strings have a gap of length g between them. The strings are symmetric about the center of the racquet: one horizontal string and one vertical string have their center lines through the center of the ring. In both directions, a string's center line sits at distance k(2r+g) from the center for every integer k with k(2r+g)<R.
The fly is a sphere of radius f. The racquet moves along a straight line perpendicular to the plane of the ring. The fly's center is inside the outer radius of the racquet and is uniformly distributed over that disk. Any overlap between the fly and the racquet (the ring or a string) counts as a hit.

The first line contains an integer N, the number of test cases.
Each of the next N lines contains f, R, t, r and g separated by exactly one space. Each number has at most 6 digits after the decimal point.
Limits
Print N lines. Line k has the form Case #k: P, where k is the test case number and P is the probability that some part of the racquet touches the fly. Print P rounded to exactly 6 digits after the decimal point.