Rods
Time limit1sMemory limit128 MB
For each rod, compute the distance from the chord midpoint to the arc midpoint after it bends into a circular arc of given arc length and chord length, rounded to an integer.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search, Math
- Solved
- No attempts yet
Problem
A laboratory at a certain company is testing a new material called politoksyparen. During the research an interesting property was discovered: a straight rod made of this material, when heated, lengthens and bends so that it turns into a circular arc whose chord is the rod's original straight shape (this property holds only for rods of very small diameter).
Suppose there are rods of very small diameter, where the -th rod has initial length (). When heated, each rod lengthens by (, with ). Lengths are measured in millimeters.
Write a program that:
- reads from standard input the number of rods and, for each rod, its length and its increase in length ;
- for each rod, computes the distance between the midpoint of the chord and the midpoint of the arc after heating (assuming the rod really bends into a circular arc); the answer must be an integer that differs from the exact value by at most ;
- writes the results to standard output.
Input
The first line contains one positive integer (). Each of the next lines contains two integers separated by a single space: the original length of the rod and its increase in length while heated .
Output
Print lines, each containing one nonnegative integer. The integer on the -th line must equal the distance between the position of the midpoint of the -th rod before and after heating, computed to the required accuracy.