zoukankan      html  css  js  c++  java
  • ZOJ 3203 Light Bulb

    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 Hh 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
    
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <algorithm>
    #include <math.h>
    #include <stdio.h>
    
    using namespace std;
    double h,H,d;
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf%lf%lf",&H,&h,&d);
            double x=sqrt((H-h)*d);
            double x2=d*h/H;
            double l=(H-h)*d/H;
            double ans;
            if(x>l&&x<d)
                ans=H+d-(2*(sqrt((H-h)*d)));
            else
                ans=max(x2,h);
            printf("%.3f
    ",ans);
           
        }
         return 0;
    }


    
    

  • 相关阅读:
    POJ 2485 Highways &amp;&amp; HDU1102(20/200)
    easyui 后台框架搭建
    启动第二个Activity
    Apache配置基于域名的虚拟主机
    POJ_1679_The Unique MST(次小生成树模板)
    MySQL学习笔记
    数据库学习之简单的SQL语句
    HDU-4643-GSM(DFS)
    Android Studio VS Eclipse (还在用Eclipse?你OUT了!)
    使用国内镜像源来加速python pypi包的安装
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228563.html
Copyright © 2011-2022 走看看