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.

name=light_bulb_1037_ddd01.gif" alt="">

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

注意精度这题最低是eps = 1e-8;

#include<cstdio>

const double eps = 1e-8;

double H, h, D;
double f(double x)
{
return H-(H-h)*D/x + D-x;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%lf%lf%lf", &H, &h, &D);
double l = D-h*D/H, r = D;
double ans = -100;
while(l+eps<r)
{
double m1 = l + (r-l)/3;
double m2 = r - (r-l)/3;
if(f(m1)<f(m2)) l = m1, ans = f(m2);
else r = m2, ans = f(m1);
}
printf("%.3f\n", ans);
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

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. [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)

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

  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. ZOJ 3203 Light Bulb(数学对勾函数)

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

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

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

  9. ZOJ - 3203 Light Bulb(三分)

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

随机推荐

  1. centos7 设备 mariadb-10

    下载地址: http://mirrors.ustc.edu.cn/mariadb/mariadb-10.0.19/source/mariadb-10.0.19.tar.gz 由于用cmake所以线安装 ...

  2. 手动安装英特尔® 凌动™ Android* x86 模拟器映像

    android的模拟器实在是太慢了,慢的让人欲仙欲死,欲罢不能.猛然发现我的电脑是intel的CPU,我勒个去,换x86模拟器.然后悲剧了,伟大的gfw 我要装sdk,我要研究android开发,到底 ...

  3. MongoDB学习笔记-命令

    连接数据库: mongodb://账号:密码@IP/库名 更多方式参考:http://www.runoob.com/mongodb/mongodb-connections.html 命令整理: 名称 ...

  4. BZOJ 2431 HAOI2009 在列的数目的顺序相反 递归

    标题效果:乞讨1~n有都布置在物种的数目相反的顺序k计划数 订购f[i][j]对于前者i原子的反向排列的数j计划数 因此,我们将第一i插入的数1~i-1该装置 能生产0~i-1反向对 再就是 f[i] ...

  5. 讲座:采用Store检查邮件(1)

    讲座:采用Store检查邮件(1) 一.邮件接收的体系结构 JavaMail API中定义了一个java.mail.Store类,用于运行邮件的接收任务,该类的实例对象封装了某种邮件接收协议的底层实施 ...

  6. Javascript作用域问题的构造函数的变量

    构造函数new对于使用.代表创建对象.此外,它可以被用作普通的函数调用,因为它也是一个功能. function Person(name) { this.name=name; } Person(12); ...

  7. AsyncSocket长连接棒包装问题解决

    project正在使用长连接快来server沟通.因此,指定我们的协议前两个字节为数据长度来区分数据包 app这边数据有两种传输形式: 1.app主动请求所须要的数据: 2.app异步接收来自服务端的 ...

  8. 不一样的味道--Html和Xml解析、格式、遍历

    很多其它内容查看官网:http://www.tinygroup.org TinyXmlParser一切以简单.有用.高速为主. 演示样例1:Xml字符串解析 比方,我们要解析一段Xml字符串,简单例如 ...

  9. HDU 4864Task(更多的联合培训学校1)(贪婪)

    职务地址:pid=4864">HDU4864 这题又是一上来觉得是最小费用流,可是边太多.果然,敲完交上去后不断TLE.. 小优化了两次也没过. . . sad.. 后来看了题解才发现 ...

  10. android 视频通话开启呼叫等待后,来第三方的视频通话,接通后通话时间一直显示为0,过几秒之后视频通话自己主动挂断

    开启通话设置视频通话的"来电等待"; 步骤1:測试机和配合机A处于视频通话过程中; 步骤2:配合机B向測试机呼出视频电话; 步骤3:測试机接听配合机B的视频来电; 现象:视频通话过 ...