Description

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

Source

ZJCPC 2009

cjx几何学的差,解不出来。发现大家都用的是三分法。第一次接触了三分法学习了一下。

三分法是一个求先单调递增然后单调递减的峰值的一个方法。可以看下下面的函数。

double work(double left , double right){
while( fabs(left-right)>eps ){
double mid=(left+right)/;
double midmid=(mid+right)/;
if(cal(mid)<=cal(midmid)){
left=mid;
}else{
right=midmid;
}
}
return left;
}

对于这题嘛!我们可以根据三角形的相似性列得这样的一个方程:l1/D=(h-l2)/(H-l2)=> l1=(h-l2)/(H-l2)*D

l1+l2=(h-l2)/(H-l2)*D+l2  (0<l2<h)  注:l1为投射到地面的影子长度,l2为投射到墙上的影子长度。

#include <stdio.h>
#include <math.h>
#define eps 1e-8 double H,h,D;
//影子长度的计算公式
double cal(double l){
return D*(h-l)/(H-l)+l;
} int main()
{
int t;
scanf("%d" ,&t);
while( t-- ){
scanf("%lf %lf %lf" ,&H ,&h ,&D);
double left=;
double right=h;
while( fabs(left-right)>eps ){
double mid=(left+right)/;
double midmid=(mid+right)/;
if(cal(mid)<=cal(midmid)){
left=mid;
}else{
right=midmid;
}
}
printf("%.3lf\n",cal(left));
}
return ;
}

TOJ 2814 Light Bulb的更多相关文章

  1. 三分 --- ZOJ 3203 Light Bulb

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

  2. Light Bulb(三分)

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

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

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

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

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

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

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

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

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

  7. ZOJ 3203 Light Bulb

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

  8. ZOJ 3203 Light Bulb(数学对勾函数)

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

  9. A. Light Bulb

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

随机推荐

  1. arcconf工具操作手册V1.0

    arcconf工具操作手册 1.1.1  arcconf工具初始化和去初始化硬盘 [命令功能] PMC阵列卡系统下初始化硬盘,可以将raw盘状态变成ready状态,以便进一步组建raid和设置热备盘: ...

  2. js作用域解析原理

    当代码进入到<script>标签或者在调用一个方法,那么就会进入作用域,在解析代码的时候就会做以下两件事情: ①去找var 和function关键字进行js预解析如果有var把值全部定义成 ...

  3. spring (1)

    相关名词: 控制反转(IoC):将对象的创建交由spring创建,1创建新class,2xml中配置 3测试context.getBean("") 类似对象工厂(工厂模式)-xml ...

  4. Apple导出p12证书 导出证书为p12 Apple开发

    1.原因说明 p12证书包含了我们的cer证书和私钥 这个证书可以当做我们开发凭证的备份 在我们更换开发机器的时候不需要再去Apple开发中心申请了 2.导出过程 2.1 打开钥匙串访问 2.2 选择 ...

  5. 【转】plsql 永久注册码适用个版本

    源地址:https://blog.csdn.net/sinat_33142609/article/details/72540025 注册码:Product Code:4t46t6vydkvsxekkv ...

  6. vs引入资源

    把资源放在程序目录中,然后点击显示所有文件,然后在资源上右键“包括在项目中”

  7. linux操作之文本编辑器

    1.文本编辑器的作用 编辑和修改系统中的那些以文本形式存在的文件(特别是各种配置文件),也可以用于 编写程序代码 2.linux下的常见编辑器 nano.Emacs.gedit.vim等 3.vim三 ...

  8. phpstudy下安装phalcon

    其实,一共也就下面几步,顺利的话,两分钟完事. 第一步:下载和当前php版本对应的php_phalcon.dll 文件 第二步:将此文件放到php版本下的ext里面. 第三步:在php.ini中添加如 ...

  9. fork 炸弹

    一段古老的Linux shell程序 :() { :|:& };: 这是bash shell的写法,首先定义了一个函数:(),花括号里面是函数体,这里递归执行函数本身,通过管道在后台再递归运行 ...

  10. Win7电脑开机无法正常启动只能进入安全模式解决方式

    我们先尝试在开机的时候按F8进入安全模式,进入到安全模式后一次打开“控制面板”-“程序与功能”,然后将卡巴斯基卸载[ http://jingyan.baidu.com/article/ff42efa9 ...