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 H, h 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
 #include<stdio.h>
#include<math.h>
double hs(double H,double h,double D,double X)
{
return D*(h-X)/(H-X)+X;//定义求长度的函数,这里的X是人在墙上的投影长度
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
double mid,midmid,l=,r=b;
do
{
mid=(l+r)/;
midmid=(mid+r)/;
if(hs(a,b,c,mid)>hs(a,b,c,midmid))
r=midmid;
else
l=mid;
}while(r-l>1e-);
printf("%.3lf\n",hs(a,b,c,mid));
}
return ;
}

主要的思想是三分法求函数的最大值,不过要注意精度我精确到1e-6都wa了,也是醉了!

建议以后都要精确到1e-9!

Light Bulb--zoj3203(三分法)的更多相关文章

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

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

  2. TOJ 2814 Light Bulb

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

  3. A. Light Bulb

    A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB   64-bit integer IO f ...

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

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

  5. 三分 --- ZOJ 3203 Light Bulb

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

  6. Light Bulb(三分)

    ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildl ...

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

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

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

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

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

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

  10. ZOJ 3203 Light Bulb

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

随机推荐

  1. ajax + php + Controller 控制所有后台函数调用

    转载请注明出处:http://www.cnblogs.com/ghypnus/p/4645873.html 好久没有来这边发布代码了 总共分成3大部分来完成php的ajax调用逻辑,以下是大致的结构 ...

  2. Delphi 10.1 Berlin 与 Delphi 10 Seattle 共存

    以下安装环境是win7 64位 1. 安装Delphi10.1 Berlin 版本. 2.修改C:\Program Files (x86)\Embarcadero\Studio\18.0\cglm.i ...

  3. Apache的prefork模式和worker模式

    prefork模式这个多路处理模块(MPM)实现了一个非线程型的.预派生的web服务器,它的工作方式类似于Apache 1.3.它适合于没有线程安全库,需要避免线程兼容性问题的系统.它是要求将每个请求 ...

  4. Linux下MySQL 5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)

    一.登录MySQL查看用SHOW VARIABLES LIKE ‘character%’;下字符集,显示如下:+--------------------------+----------------- ...

  5. 大端模式&小端模式、主机序&网络序、入栈地址高低问题

    一.大端模式&小端模式 所谓的“大端模式”,是指数据的低位(就是权值较小的后面那几位)保存在内存的高地址中,而数据的高位,保存在内存的低地址中,这样的存储模式有点儿类似于把数据当作字符串顺序处 ...

  6. JS 输出对象的属性以及方法[转载]

    <script>var obj  = {attribute:1,method:function() {alert("我是函数");}}for (var i in obj ...

  7. 2013第51周二eclipse启动优化

    2013第51周二eclipse启动优化 今天注意到了eclipse.ini配置文件中gc.log--在eclipse启动时清空,然后记录了eclipse每次运行过程中的gc分配情况,看到了一篇很好的 ...

  8. Dos命令---ipconfig

    Dos命令---ipconfig 作者:vpoet mail:vpoet_sir@163.com ipconfig是很常用的Dos命令,我们可以用ipconfig /?查看该命令的说明.在linux下 ...

  9. 【POJ 1236 Network of Schools】强联通分量问题 Tarjan算法,缩点

    题目链接:http://poj.org/problem?id=1236 题意:给定一个表示n所学校网络连通关系的有向图.现要通过网络分发软件,规则是:若顶点u,v存在通路,发给u,则v可以通过网络从u ...

  10. 兼容各个浏览器的H.264播放: H.264+HTML5+FLOWPLAYER+WOWZA+RMTP

    一.方案确定 计划做视频播放,要求可以播放H264编码的mp4文件,各个浏览器,各种终端都能播放. 首先查找可行性方案, http://www.cnblogs.com/sink_cup/archive ...