Ball Bearings
Time limit1sMemory limit128 MB
Given the inner diameter of an outer ring, the ball diameter, and the minimum gap between neighboring balls, find the maximum number of balls that fit.
- Level
Easy3 of 10
- Topics
- Geometry, Math, Implementation, Binary search
- Solved
- No attempts yet
Problem
The Swedish company SKF makes ball bearings. A ball bearing is one of the two types of rolling (anti-friction) bearings; the other is the roller bearing.
Its function is to connect two machine members that move relative to one another so that the frictional resistance to motion is minimal. In many applications one member is a rotating shaft and the other a fixed housing. Each ball bearing has three main parts: two grooved, ring-like races and a number of balls. The balls fill the space between the two races and roll with negligible friction in the grooves. The balls may be loosely restrained and separated by a retainer (cage).
Presumably, the more balls you fit inside the outer ring, the smoother the ride will be, but how many can you fit? You are given the inner diameter of the outer ring, the diameter of the balls, and the minimum distance between neighboring balls. Compute the maximum number of balls that fit on the inside of the outer ring. Every ball must touch the outer ring.

Input
The first line contains a positive integer , the number of test cases. Each of the following lines describes one test case with three positive floating-point numbers , , : is the inner diameter of the outer ring, is the diameter of a ball, and is the minimum distance between neighboring balls. Every value lies in the range .
Output
For each test case, output a single integer on its own line: the maximum number of balls that fit in the ball bearing under the constraints above. There will always be room for at least three balls.