zoukankan      html  css  js  c++  java
  • 三分板子

    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
    ",F((lmid+rmid)/2));
        }
    }
     
    Sample Output
     
    1.000
    0.750
    4.000
    刀剑映出了战士的心。而我的心,漆黑且残破
  • 相关阅读:
    关于域名备案申请
    meta标签中的http-equiv属性使用介绍
    WDCP3.3中多PHP版本安装方法,以及安装遇到的问题
    模拟《意尔康》网站加载动画效果
    如何提示系统所在的浏览器版本过低?
    Dedecms升级php版本{dede:field.body/}不解析,文章内容不显示
    微信weixin://xxx 分析
    SuperSlide之属性targetCell介绍
    了解JSON Web令牌(JWT)
    如何向这些CA来申请数字证书呢?
  • 原文地址:https://www.cnblogs.com/OIEREDSION/p/11275631.html
Copyright © 2011-2022 走看看