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. MySql语句大全:创建、授权、查询、修改等(转)

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 一.用户创建.权限.删除 1.连接MySql操作 连接:mysql -h 主机地址 -u 用户 ...

  2. Quick Tip: How to Add Syntax Highlighting to Any Project

    Quick Tip: How to Add Syntax Highlighting to Any Projectpublic String showAllArticleForPage() throws ...

  3. BackGroundWorker使用总结

    方法: backgroundWorker1.CancelAsync() 用于取消异步执行 backgroundWorker1.ReportProgress(int ,object)用于向主线层报告进度 ...

  4. 白板编程浅谈——Why, What, How(转)

    原文链接:http://lucida.me/blog/whiteboard-coding-demystified/ 这篇文章节选自我正在撰写的一本关于应届生面试求职的书籍,欢迎在评论或微博(@peng ...

  5. 在Apk应用程序内,查找某个Activity。

    转载请注明出处:http://blog.csdn.net/droyon/article/details/39933677 Intent intent = new Intent(Intent.ACTIO ...

  6. HDU 2017 一系列统计数据

    一系列统计数据 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  7. 【Java GUI】Java面板基础:JPanel

    有两个面板,常见的面板(JPanel)和滚动面板(JScrollPane) Jpanel 面板是一种常见的容器,JPanel的作用是实现接口层次结构,面放入一些组件.也能够在上面绘画,将放有组件和有画 ...

  8. [LeetCode] Regular Expression Matching [6]

    称号: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...

  9. 科技股晴间多云 阿里京东IPO或受影响

    微博的时间长达一个月的时间才上市.科技股一直笼罩. Facebook一个月股价下跌21.55%:特斯拉跌幅21.69%:亚马逊的股价相比,1一个月27日高点下跌22.13%. 以前的明星股票都已进入华 ...

  10. OpenCV:Mat元素访问方法、演出、代码的复杂性和安全性分析

    欢迎转载.尊重原创,因此,请注明出处: http://blog.csdn.net/bendanban/article/details/30527785 本文讲述了OpenCV中几种訪问矩阵元素的方法, ...