TOJ 2814 Light Bulb
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
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的更多相关文章
- 三分 --- ZOJ 3203 Light Bulb
Light Bulb Problem's Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...
- Light Bulb(三分)
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildl ...
- ZOJ 3203 Light Bulb - 求导求最大值
如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...
- zoj 3203 Light Bulb,三分之二的基本问题
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- ZOJ 3203 Light Bulb (三分+计算几何)
B - Light Bulb Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- ZOJ 3203 Light Bulb (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- ZOJ 3203 Light Bulb
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...
- ZOJ 3203 Light Bulb(数学对勾函数)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- A. Light Bulb
A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO f ...
随机推荐
- java 七牛上传图片到服务器(采用的html5 压缩 传输base64方式)
//html 页面如下<div class="form-group"> <label class="col-sm-2 control-label&quo ...
- docker run hello-world失败
提示镜像拉取失败,解决方案 到 https://cr.console.aliyun.com/ 注册一个账户 列表中就有 加速器 启动 Docker 端 右键 选择配置 在Docker Dae ...
- hbase0.92 数据修复
现有集群环境:8台region server.1台master server 早晨重启某一region server后,该server的region全部下线未恢复. 重启前 hbase(main):0 ...
- python 时间相关函数
python 中与时间处理相关的模块包括 time.datetime.以及 calendar time 模块 time() 函数:time() 函数用于返回当前时间的时间戳(1970年01月08时00 ...
- jQuery EasyUI Datagrid组件默认视图分析
在Datagrid基础DOM结构的一文中,我对Datagrid组件的骨架做了很详细的描述.有了骨架还并不完整,还得有血有肉有衣服穿才行.强大的Datagrid组件允许我们自己定义如何在基础骨架上长出健 ...
- 3 hql语法及自定义函数(含array、map讲解) + hive的java api
本博文的主要内容如下: .hive的详细官方手册 .hive支持的数据类型 .Hive Shell .Hive工程所需依赖的jar包 .hive自定义函数 .分桶4 .附PPT hiv ...
- 【Leetcode】Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- JavaWeb学习笔记(四)—— response
一.response概述 response是Servlet.service方法的一个参数,类型为javax.servlet.http.HttpServletResponse.在客户端发出每个请求时,服 ...
- Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement
原因: 此异常的原因是由于mapper接口编译后在同一个目录下没有找到mapper映射文件而出现的.由于maven工程在默认情况下src/main/java目录下的mapper文件是不发布到targe ...
- Android 系统特有的类介绍及使用
1.Content类 在应用程序中Context的具体实现子类就是:Activity,Service,Application.可以把它理解成存储东西的仓库. 常用的上下文一般是类名.class或类名. ...