Zoj 3203 Light Bulb, Two-thirds of the basic questions

Source: Internet
Author: User

Light Bulb Time limit: 1 Second Memory Limit: 32768 KB

Compared to Wildleopard's wealthiness, his brother Mildleopard is rather poor. His house is narrow and he have only one light bulb in the He house. Every night, he is wandering in his incommodious house, and thinking of how to earn. One day, he found that's the length of his shadow is changing from time to time while walking between the light bulb and th E wall of his house. A Sudden thought ran through his mind and he wanted to know the maximum length of his shadow.

Name=light_bulb_1037_ddd01.gif ">

Input

The first line of the input contains an integer t (T <=), indicating the number of cases.

Each test case contains three real numbers H, H and D on one line. h is the height of the bulb while H is the height of mildleopard. D is distance between, the light bulb and the wall. All numbers is in range from 10-2 to 103, both inclusive, and H - H >= 10-2.

Output

For each test case, the output of the maximum length of Mildleopard ' s shadow on one line, accurate up to three decimal places.

Sample Input

32 1 0.52 0.5 34 3 4

Sample Output

1.0000.7504.000





Note the accuracy of this problem is the lowest EPS = 1e-8;


#include <cstdio>const double eps = 1e-8;double h, h, d;double f (double x) {    return H (h-h) *d/x + d-x;} int main () {    int t;    scanf ("%d", &t);    while (t--)    {        scanf ("%lf%lf%lf", &h, &h, &d);        Double L = d-h*d/h, r = D;        Double ans = -100;        while (L+eps<r)        {            Double m1 = l + (r-l)/3;            Double m2 = R-(r-l)/3;            if (f (M1) <f (m2)) L = m1, ans = f (m2);            else R = m2, ans = f (m1);        }        printf ("%.3f\n", ans);    }    return 0;}


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Zoj 3203 Light Bulb, Two-thirds of the basic questions

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.