C. Circle

Source: Internet
Author: User

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 ;}










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.