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. ElasticSearch 笔记(二)

    记录一些核心概念 1) Near Realtime (NRT): 近实时,包括 2 个方面,① 数据从写入 Elasticsearch 到可被搜索.分析的延迟 ( 大约 1 秒 ); ② 从 es 中 ...

  2. CSRF漏洞详细说明

    CSRF漏洞详细说明 通常情况下,有三种方法被广泛用来防御CSRF攻击:验证token,验证HTTP请求的Referer,还有验证XMLHttpRequests里的自定义header.鉴于种种原因,这 ...

  3. C# enum 枚举 反射

    枚举遍历 public enum EMyType { [System.ComponentModel.Description("A类型")] TypeA = 1, [System.C ...

  4. T-SQL查询进阶--SQL Server中的事务与锁

    为什么需要锁 在任何多用户的数据库中,必须有一套用于数据修改的一致的规则,当两个不同的进程试图同时修改同一份数据时,数据库管理系统(DBMS)负责解决它们之间潜在的冲突.任何关系数据库必须支持事务的A ...

  5. 以太坊系列之三: 以太坊的crypto模块--以太坊源码学习

    以太坊的crypto模块 该模块分为两个部分一个是实现sha3,一个是实现secp256k1(这也是比特币中使用的签名算法). 需要说明的是secp256k1有两种实现方式,一种是依赖libsecp2 ...

  6. 自建脚手架之配置中心--LightConf的实现

    常规项目开发过程中, 通常会将配置信息位于在项目resource目录下的properties文件文件中, 配置信息通常包括有: jdbc地址配置.redis地址配置.活动开关--等等.因此每次上线或者 ...

  7. sqlServer sa用户登陆失败的解决办法

    sqlserver sa用户登陆失败的解决办法 如下图以此模仿: 1.右键-属性 2.找到安全: 3.勾选如图: 4.sa用户密码重置: 5.服务重启:

  8. 基于stor2RRD 的 SAN、存储监控

    一. 配置用法在官网都有的详见网页: http://www.stor2rrd.com/install.htm?1.2 二 . 在这里我只是想记录一下我是如何编译安装Apache的,避免踩坑: 安装包如 ...

  9. MVC进阶篇(四)——[HttpGet]和[HttpPost]

    前言 Get和post,一个获取请求,一个提交请求,在MVC里面用法也很特别,总结一下,我理解的不是特别深刻,希望多多交流. 内容 [HttpGet] 需求: 用户想要通过点击修改按钮来达到修改这部分 ...

  10. centos下安装memcached并设置开机自动启动-两种方法

    方法一: 安装memcachedyum install memcached 启动服务并初始化service memcached start -p 11211 -l 127.0.0.1 -d 设置mem ...