zoukankan      html  css  js  c++  java
  • ZOJ 3203 Light Bulb (三分+计算几何)

    B - Light Bulb
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

    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. D is 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
    

    Sample Output

    1.000
    0.750
    4.000
    
    题目意思:
    给你H,h,D三个数字
    问你影子的长度
    随着h的变化,影子的长度也会变化(影子的长度包括在地上和墙上的)
    可以预想一下
    跟h有关的影子的长度的函数是一个由峰值的函数
    所以三分解决
     
    #include<cstdio>
    #include<string>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<cctype>
    #include<stack>
    #include<sstream>
    #include<list>
    #include<assert.h>
    #include<bitset>
    #include<numeric>
    #define max_v 35
    #define eps 10e-6
    using namespace std;
    double H,h,D;
    double f(double l)
    {
        return D*(h-l)/(H-l)+l;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf %lf %lf",&H,&h,&D);
            double l=0,r=h;
            double mid,mmid;
            while(fabs(l-r)>eps)
            {
                mid=(l+r)/2;
                mmid=(mid+r)/2;
                if(f(mid)<=f(mmid))
                {
                    l=mid;
                }
                else
                {
                    r=mmid;
                }
            }
            printf("%0.3lf
    ",f(l));
        }
        return 0;
    }
    /*
    题目意思:
    给你H,h,D三个数字
    问你影子的长度
    
    随着h的变化,影子的长度也会变化(影子的长度包括在地上和墙上的)
    可以预想一下
    跟h有关的影子的长度的函数是一个由峰值的函数
    所以三分解决
    
    */
     
  • 相关阅读:
    DotNetty 实现 Modbus TCP 系列 (一) 报文类
    C# 获取文件详细备注信息 (如图片、视频实际创建时间)
    Java 下载 HLS (m3u8) 视频
    开源 DotNetty 实现的 Modbus TCP/IP 协议
    SQL Server 2008 开启远程连接
    在 Web 页面使用 VLC 插件播放 m3u8 视频流 (360 极速模式)
    在 Web 页面中使用离线地图
    使用 Travis CI 自动部署 Hexo 站点至 GitHub Pages
    BZOJ 3238: [Ahoi2013]差异((单调栈+后缀数组)/(后缀树))
    BZOJ 3998: [TJOI2015]弦论(后缀自动机)
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9504080.html
Copyright © 2011-2022 走看看