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. JS连等赋值的坑

    cnblogs标题: JS连等赋值的坑 关于JS连等赋值有个经典的笔试题: var a = {n: 1}; var b = a; a.x = a = {n: 2}; console.log(a.x); ...

  2. python全栈开发之OS模块的总结

    OS模块 1. os.name()      获取当前的系统 2.os.getcwd      #获取当前的工作目录 import os cwd=os.getcwd() # dir=os.listdi ...

  3. 转:[NHibernate]视图处理

    转自:http://www.cnblogs.com/wolf-sun/p/4082899.html 目录 写在前面 文档与系列文章 视图 一个例子 总结 写在前面 前面的文章主要讲了对物理数据表的操作 ...

  4. CNN学习笔记:卷积运算

    CNN学习笔记:卷积运算 边缘检测 卷积 卷积是一种有效提取图片特征的方法.一般用一个正方形卷积核,遍历图片上的每一个像素点.图片与卷积核重合区域内相对应的每一个像素值乘卷积核 .内相对应点的权重,然 ...

  5. Python 中全局变量的实现

    一.概述 Python 中全局变量的使用场景不多,但偶尔也有用武之处. 如在函数中的初始化,有时需要从外部传入一个全局变量加以控制.或者在函数中,使用连接池时,也可能有使用全局变量的需要. 广义上的全 ...

  6. Poj 2074 Line of Sight

    地址:http://poj.org/problem?id=2074 题目: Line of Sight Time Limit: 1000MS   Memory Limit: 30000K Total ...

  7. ado.net(增删改)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 存在单点故障的namenode宕机恢复测试

    前提:如果namenode没有做HA,那么至少应该启用secondarynamenode,以便namenode宕机之后手动恢复数据 实验环境:3个节点(cenos 6.10) 测试前数据: 1.为了确 ...

  9. (+4)2.2UML建模图

    ①用例图 [用途]:帮助开发团队以一种可视化的方式理解系统的功能需求. 用例图所包含的元素如下: 1. 参与者(Actor) 表示与您的应用程序或系统进行交互的用户.组织或外部系统.用一个小人表示. ...

  10. Google揭露SHA-1碰撞,加速数据重删字节对比

    原创 架构师技术联盟  近期,Google和道荷兰阿姆斯特研究者宣布攻破了世界上第一例公开的SHA-1哈希碰撞实例,业界一片哗然.当两组不同的数据(文件.一段数据)计算出相同的Hash值时,即视为二者 ...