ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

三分板子

2019-07-31 13:03:44  阅读:258  来源: 互联网

标签:his rmid double 板子 lmid house bulb 三分


B - Light Bulb
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld
 & %llu
Submit Status Practice ZOJ
 3203  
Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found
 that the length of his shadow was changing from time to time while walking between the light bulb and the 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 <= 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 is the height of mildleopard. Dis distance between the light bulb and the wall. All numbers
 are in range from 10-2 to 103, both inclusive, and H - h >= 10-2.     Output
For each test case, output the maximum length of mildleopard's shadow in one line, accurate up to three decimal places..     Sample Input   3
2 1 0.5
2 0.5 3
4 3 4     每次分一个  rmid 再相当于4分 算lmid    code:
//
#include<iostream>
#include<cstdio>
using namespace std;
int T;
double H,h;
double D;
double F(double x)
{
    return ((h-x)/(H-x))*D+x;
}
int main()
{
    cin>>T;
    while(T--)
    {
        cin>>H>>h>>D;
        double  r=h;
        double l=0;
        double rmid=(l+r)/2;
        double lmid=(rmid+l)/2;
        while(rmid-lmid>=1e-9)
        {
            if(F(lmid)>=F(rmid))
            {
                r=rmid;
            }
            else
            l=lmid;
         rmid=(l+r)/2;
         lmid=(rmid+l)/2;
        }
        printf("%.3lf\n",F((lmid+rmid)/2));
    }
}

 

  Sample Output   1.000
0.750
4.000

标签:his,rmid,double,板子,lmid,house,bulb,三分
来源: https://www.cnblogs.com/OIEREDSION/p/11275631.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有