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 ...
随机推荐
- React学习笔记4
遇到的问题 目前模板是自己任意定义的,样式不好控制 在组件设计时,可以把页面数据显示的地方,分割父子组件嵌套的结构,比如,商品数据显示列表,把组外层容器看成是父组件,里面是数据显示的渲染模板,看成是子 ...
- C# 多线程操作实例
1.多线程操作 一旦打开线程就必须记得关闭 1.第一部分 这是个数字叠加小功能 private void CountTo(int countTo, CancellationToken ct) { ; ...
- Go环境搭建(Windows)
下载MSI MSI地址 配置环境变量 GOPATH: 用于存放Go语言Package的目录,这个目录不能在Go的安装目录中 GOBIN: Go二进制文件存放目录,写成%GOROOT%\bin就好 PA ...
- 使用C/C++代码编写Python模块
假如我们要用C语言实现下面的python脚本bird.py import os def fly(name): print(name + " is flying.\n") 调用脚本m ...
- MongoDB 副本集配置,开启账号认证
MongoDB 自带功能强大的主从,配置也很简单,从零开始花了30分钟搞定 3台以上机器IP: 192.168.1.24, 192.168.1.25, 192.168.1.26, 192.168.1. ...
- loj #6122. 「网络流 24 题」航空路线问题
#6122. 「网络流 24 题」航空路线问题 题目描述 给定一张航空图,图中顶点代表城市,边代表两个城市间的直通航线.现要求找出一条满足下述限制条件的且途经城市最多的旅行路线. 从最西端城市出发,单 ...
- form表单提交回调函数
form表单没有回调函数,不过可以通过jquery-form.js这个插件来实现回调函数: <form id="addform" class="form-horiz ...
- 《Andrew Ng深度学习》笔记2
神经网络基础 1.图计算 计算时有两种方法:正向传播和反向传播.正向传播是从底层到顶层的计算过程,逐步推出所求公式.反向传播是从顶层到底层,从已知的式子求出因变量的影响关系. 在这里用到的反向传播算法 ...
- 微信小程序之页面之间传递值
页面之间传值有三种方式 1.url传值 2.本地存储传值 3.全局变量传值 1.url传值: 通过url传值的需要通过option来获取参数值. 更多详情可以访问小程序-navigateTo章节. A ...
- asp.net MVC中的@model与Model
asp.net MVC中的@model与Model https://blog.csdn.net/ydm19891101/article/details/44301201 在MVC的实际使用中,我们经常 ...