【3点】【清華合宿2015】電球


                                       Light Bulb
                    Time Limit: 1 Second      Memory Limit: 32768 KB
ZJOIにしかないようです.住所を貼ってください.http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3366
Compred to wildleopard’s wealthiness,his broother millooland is rather poor.His house is narrow and he has only one light bulb in his house.Every night,heis wandering in his incommous house.hone,thinemorn.morne.morne.morne.more.he found that the length of his show was change from time while walking between the light bulb and the wall of his house.A Stand thought rand through mind and he wanted to know the maximutem.shows.shows.shows.
Input
The first line of the input contains an integer T(T<=100)、indicating the number of cases.
Each test case contains three real numbers H,h and D in one line.H is the height of the light bulb while h the height of miltleopard.D is distance between the light bulb and the wall.All numbers clranger 10-103
Output
For each test case、output the maximum length of mildleopard’s show in one line、accurate up to three decimal placces…
Sample Input
3 1 0.5 2 0.5 3 3 3 Sample Output
1.000 0.750 4.000
分析:三分法を分けて、テンプレートの問題、多種類の状況を考慮することに注意します.私が挙げた答えは地上の影の長さです.第一の場合:壁に影がない、下の図のような【三分】【清华集训2015】灯泡_第1张图片の第二の場合:壁に影がある、下の図のような【三分】【清华集训2015】灯泡_第2张图片の場合、既知の量と私達が列挙した地上の影の長さを通じてxを求めることができます.最終的に(x+D-地上影の長さ>D)がtrueかどうかを判断します.それに対応した対策をして、具体的にはコードを見て、コメントがあります.
#include 
using namespace std; 
double h,H,d,Left,Right,rMid,lMid,a; 
inline double f(double x) 
{ 
    double y=h*(d-x)/(H-h); //   y      x,   x          
    if(y+d-x>d) //     
    { 
        return x+(h*d-H*x)/(d-x); //                ,          
    } 
    else 
    { 
        return y; //     
    } 
} 
int main() 
{ 
    int t; 
    scanf("%d",&t); 
    while(t--) 
    { 
        scanf("%lf%lf%lf",&H,&h,&d); 
        Left=0,Right=d; 
        while(Right-Left>0.0001) //        
        { 
            lMid=Left+(Right-Left)/3; 
            rMid=Right-(Right-Left)/3; 
            if(f(lMid)<=f(rMid)) Left=lMid; 
            else Right=rMid; //    
        } 
        printf("%.3lf
",f(Left)); // } return 0; }
ありがとうございます.