Zoj3203--light Bulb (three-part method)

Source: Internet
Author: User
Tags time limit
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.

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

3
2 1 0.5
2 0.5 3
4 3 4

Sample Output

1.000
0.750
4.000
Analysis: When a person from the wall just have a shadow on the right to walk to the wall, the shadow of the total length of the shadow on the wall of the convex function
      Three-point shadow on the wall long ...
Code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double lim=1e-6;
Double l,r;

Double h,h,d;
int test;

Double calc (double x)
{
    return x+ (d* (h-x)/(H-x));
}

Double sf ()
{
    double m1,m2,mid;
    Do
    {
        mid= (r-l)/3;
        M1=l+mid;m2=r-mid;
        if (Calc (M1) <calc (m2)) l=m1; else r=m2;
    } while (R-l>lim);
    Return calc (l);
}

void ReadData ()
{
    freopen ("zoj3203.in", "R", stdin);
    Freopen ("Zoj3203.out", "w", stdout);
    scanf ("%d", &test);
    while (test--)
    {
        scanf ("%lf%lf%lf", &h,&h,&d);
        L=0;r=h;
        printf ("%.3lf\n", SF ());
    }
}

int main ()
{
    readdata ();
    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.