Light Bulb


Time Limit: 1 Second      Memory Limit: 32768 KB

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


Author: GUAN, Yao
Source: The 6th Zhejiang Provincial Collegiate Programming Contest

#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int t;
double h,H,D;
int main()
{
while(~scanf("%d",&t))
{
for(;t>;t--)
{
scanf("%lf%lf%lf",&H,&h,&D);
//最优解在[x0,x2]之间,如果能取到x1,则影子最长
//影子长度在此区间内,符合倒钩函数l=H+D-x-D*(H-h)/x
double x0=D*(H-h)/H;//在墙壁上的影子长度为0时,人与灯的距离
double x1=sqrt(D*(H-h));
double x2=D;//人不断向后移(也就是向墙壁移动),最远到墙壁,人与灯的距离
double x;
if (x0<=x1 && x1<=D) x=x1; //区间包含x1
else if(x2<=x1) x=x2;//区间在x1的左边,即最大值小于x1
else if(x0>=x1) x=x0;//区间在x1的右边,即最小值大于x1
printf("%.3lf\n",H+D-x-D*(H-h)/x);
}
}
return ;
}

ZOJ 3203 Light Bulb(数学对勾函数)的更多相关文章

  1. ZOJ 3203 Light Bulb (三分+计算几何)

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

  2. 三分 --- ZOJ 3203 Light Bulb

    Light Bulb Problem's Link:   http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...

  3. ZOJ 3203 Light Bulb (三分查找)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  4. ZOJ 3203 Light Bulb - 求导求最大值

    如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...

  5. zoj 3203 Light Bulb,三分之二的基本问题

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  6. ZOJ 3203 Light Bulb

    Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...

  7. [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)

    Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...

  8. ZOJ 3203 Light Bulb( 三分求极值 )

    链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...

  9. ZOJ - 3203 Light Bulb(三分)

    题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...

随机推荐

  1. CF 558 C. Amr and Chemistry 暴力+二进制

    链接:http://codeforces.com/problemset/problem/558/C C. Amr and Chemistry time limit per test 1 second ...

  2. HDU1081:To The Max(最大子矩阵,线性DP)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1081 自己真够垃圾的,明明做过一维的这种题,但遇到二维的这种题目,竟然不会了,我也是服了(ps:猪啊). ...

  3. C#数组的笔记

    Array.Copy的笔记: 1.将值类型的元素装箱位引用类型的元素,比如讲一个Int32[]的元素复制到Object[]中 2.将引用类型的元素拆箱为值类型的元素 3.加宽CLR基元值类型,比如讲一 ...

  4. 并行求pi (C++实现)

    用OpenMP并行化求pi的代码,这里用的是公式法求pi.具体如下: //公式法 #include<omp.h> #include<stdio.h> #include<s ...

  5. 华为大数据项目fusionInsight

    项目简述:基于开源Hadoop2.0架构的集群网络,进行海量数据的分布式计算.由于Hadoop集群规模不断扩大,而搭建一个同等规模的测试集群需要一笔昂贵的开销.目前有100台左右物料,期望预测计算节点 ...

  6. s5_day12作业

    # day12作业: # 功能实现: # 一个文件夹中,存在多个文件,包括图片,视频,文本等等, # 遍历出时间在2017-06-05至2017-06-09这段时间内创建的所有文件.具体文件夹,自己创 ...

  7. NHibernate MappingException. No Persister

    在另一个Visual Studio项目(议会mm.k.Infrastructure)我有我的映射文件(一个映射目录),我的hibernate.cfg.xml和一些仓库. 这是我的映射文件: <? ...

  8. Python 中的条件运算符

    一.概述 在 C.Java 等语言中,有一种常见的条件运算符,又叫"三目运算符". 详情参见 [条件运算符-wikipedia][https://zh.wikipedia.org/ ...

  9. 对Java的接口和抽象类 的一些了解

    学习并转载自: https://mp.weixin.qq.com/s?__biz=MzAxMzQ3NzQ3Nw==&mid=2654251476&idx=4&sn=e66ec4 ...

  10. redis 笔记03 RDB 持久化、AOF持久化、事件、客户端

    RDB 持久化 1. RDB文件用于保存和还原Redis服务器所有数据库中的所有键值对数据. 2. SAVE命令由服务器进程直接执行保存操作,所以该命令会阻塞服务器. 3. BGSAVE由子进程执行保 ...