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. Sql--IDENTITY()自动增长列

    CREATE TABLE Tables( , ) ,) NOT NULL, [UpdateTime] [datetime] NOT NULL, CONSTRAINT [PK_Tables] PRIMA ...

  2. C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF

    之前用C++简单的写了一个demo 现在用C#写了完整版 定义字符 定义发送数量 定义发送对象 注意事项 QQ必须单独一个窗体 微信对象在输入名字的时候必须写微信 源代码 using System; ...

  3. openvpn的搭建与应用

    一.VPN概述: VPN(Virtual Private NetWork,虚拟专用网络)架设在公共共享的基础设施互联网上,在非信任的网络上建立私有的安全的连接,把分布在不同地域的办公场所.用户或者商业 ...

  4. 单机,伪分布式,完全分布式-----搭建Hadoop大数据平台

    Hadoop大数据——随着计算机技术的发展,互联网的普及,信息的积累已经到了一个非常庞大的地步,信息的增长也在不断的加快.信息更是爆炸性增长,收集,检索,统计这些信息越发困难,必须使用新的技术来解决这 ...

  5. 局域网内搭建一个服务器,可以使用 https 吗

    https://www.v2ex.com/t/472394 这是一个创建于 126 天前的主题,其中的信息可能已经有所发展或是发生改变. 局域网内通过嵌入式设备搭建一个轻量级 web 服务,可以仍然使 ...

  6. selenium+PhantomJS简单爬虫

    #!/usr/bin/env python # -*- coding: utf-8 -*- ''' Created on 2017年10月19日 @author: zzy ''' import tim ...

  7. 魔方方法之--类的构造(__init__,__new__)和析构(__del__)方法

    构造方法(参见小甲鱼入门教程) __ init__()方法:类的初始化方法,初始化类对象时被调用,需要的时候再调用它 注意点:这个方法的返回值必须是None class Rectangle(): de ...

  8. POJ-3468-A Simple Problem with Integers(线段树 区间更新 区间和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 139191 ...

  9. ajax(Asynchronous JavaScript and XML) 异步js或者xml

    1.XMLHttpRequest 对象:向服务器发送局部的请求,异步获取执行 a.浏览器支持 b.语法: xmlhttp==new XMLHttpRequest(); xmlhttp.open(&qu ...

  10. gnome-terminal

    在终端中打开终端: gnome-terminal 同时打开多个终端: gnome-terminal --window --window 此处有几个 --window 就会打开几个终端 最大化形式打开终 ...