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. Android自定义属性:attr.xml 与 TypedArray

    1.attr.xml <?xml version="1.0" encoding="utf-8"?> <resources> <de ...

  2. APP中关于Android和IOS与网页交互

    安卓交互: //安卓js代码start function bntcat(){ if(isAndroid){ musicPause() } var str = '{"tips":20 ...

  3. LINQ不包含列表

    var query=lista.Where(p=>!listb.Any(g=>p.id==g.id && p.no==g.no))

  4. Spark学习笔记--安装SCALA和IDEA开发环境

    一:安装Scala

  5. 使用反射实现 webdriver page 类

    这个类的目的是为了简化page类的实例化,只需要定义public page成员变量 然后再 启动driver后 通过反射实例化page 后面可以直接点出page实例 package crazy.sel ...

  6. linux 相关使用总结

    1. 在centos下安装g++,如果输入 yum install g++,那么将会提示找不到g++.因为在centos下g++安装包名字叫做:gcc-c++ 所以应该输入 yum install g ...

  7. jquery扩展鼠标mousewheel事件

    最近项目中要有个鼠标在图片上滚动实现图片放大和缩小的得到功能,隐约的记得好像记得有个 mousewheel 事件,可以实现需求,于是乎,开始在网上查找这一方法,但是,出乎意料的结果,各浏览器对此方法有 ...

  8. ES6 随记(3.4.1)-- 函数的拓展(参数默认值,扩展运算符)

    上一章请见: 1. ES6 随记(1)-- let 与 const 2. ES6 随记(2)-- 解构赋值 3. ES6 随记(3.1)-- 字符串的拓展 4. ES6 随记(3.2)-- 正则的拓展 ...

  9. [HEOI2016/TJOI2016]求和(第二类斯特林数)

    题目 [HEOI2016/TJOI2016]求和 关于斯特林数与反演的更多姿势\(\Longrightarrow\)点这里 做法 \[\begin{aligned}\\ Ans&=\sum\l ...

  10. jQuery音乐播放器jPlayer

    在线演示 本地下载