There are two circles. to place them in a rectangle, the bottom of the two circles must be tangent to the bottom of the rectangle, and the shortest width D of the rectangle must be obtained.
Input
The input file has multiple rows and each line has two integers. The format is as follows:
R1 R2 R1, R2 is the radius of the two circles, 0 <R1, R2 <= 100 R1 = 0, R2 = 0 when the input ends output
For each group of input data, use a single row to output the minimum value of D and keep it to two decimal places.
Sample Input
3 30 0
Sample output
12.00
Solution:
As shown in, there are two cases.
The Code is as follows:
/* Two cases: 1: The two circles do not have much difference. The two circles are tangent to the bottom and are tangent to both sides respectively. 2: one of the two circles is particularly large, its diameter is the shortest width d, and the other circle is in the gap between it and the edge */# include <stdio. h> # include <math. h> int main () {int R1, R2, Max; double D; while (scanf ("% d", & R1, & R2 )) {If (r1 = 0 & r2 = 0) break; max = r1> R2? R1: R2; D = SQRT (R1 + R2) * (R1 + R2)-(r1-r2) * (r1-r2 )); if (R1 + r2 + D <2.0 * max) {printf ("%. 2lf \ n ", 2.0 * max);} else {printf (" %. 2lf \ n ", R1 + r2 + d) ;}} return 0 ;}