ZOJ 3203 Light Bulb - 求导求最大值

如果L全在地面上:
输出 h * D / H
如果L全在墙上:
输出 h
否则:
(D - X ) / X = Y / (H - h)
L = D - X + h - Y
然后对L求导即可
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std; int main(){
double H,h,D,x,y,x0;
int t;
scanf("%d",&t);
while(t--){
scanf("%lf%lf%lf",&H,&h,&D);
x0 = D - h * D / H;
x = sqrt( D * (H - h) );
y = (D - x) * (H - h) / x;
if(x >= D) printf("%.3lf\n",h);
else if(x < x0) printf("%.3lf\n",h * D / H);
else printf("%.3lf\n",h - y + D - x);
}
return ;
}
Light Bulb
Time Limit: 1 Second Memory Limit: 32768 KB
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
ZOJ 3203 Light Bulb - 求导求最大值的更多相关文章
- ZOJ 3203 Light Bulb( 三分求极值 )
链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...
- ZOJ 3203 Light Bulb (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- 三分 --- ZOJ 3203 Light Bulb
Light Bulb Problem's Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...
- 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,三分之二的基本问题
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 ...
- [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)
Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...
- ZOJ - 3203 Light Bulb(三分)
题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...
随机推荐
- app自动化的webView页面测试思路(appium工具)。
1.获取当前activity多有的handles,然后去遍历它,发现webView后切换到webView对应模式,就可以了.进一步操作webView的话用下面的方法(driver.getPageSou ...
- c# zip file and folder programmatically
In .net 4.5 Framework, we can zip a file by this way: private static string CompressFile(string sour ...
- HTML5 appcache
参考http://www.zation.me/2013/05/28/build_offline_mobile_web_app.html 他的事件总结的比较好 checking:客户端正在检查manif ...
- 用Mediawiki做百科网站资源大参考
MediaWiki简易安装教程**关于mediawiki 一些好的资料: http://codex.wordpress.org.cn/Mediawiki%E5%BB%BA%E7%AB%99%E7%BB ...
- HDOJ 1427(dfs) 速算24点
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路分析: 题目要求判断是否存在一种运算组合使得4个数的计算结果为24,因为搜索的层次为3层,不 ...
- JAVA ThreadPoolExecutor(转)
原文链接:http://blog.csdn.net/historyasamirror/article/details/5961368 基础 在我看来,java比C++的一个大好处就是提供了对多线程的支 ...
- 自己动手写Java大整数《3》除法和十进制转换
之前已经完毕了大整数的表示.绝对值的比較大小.取负值.加减法运算以及乘法运算. 详细见前两篇博客(自己动手写Java * ). 这里加入除法运算. 另外看到作者Pauls Gedanken在blog( ...
- 获取WebView里的网页文本内容
获取WebView里的网页文本内容,能够採用例如以下方法: public class ComJSInterface { public void loadHtmlContent(String conte ...
- Webstorm入门-----常用快捷键
为了提高敲代码的速度.我们所需要关注的各种快捷键: 首先,快捷键的设置 相关连接: http://www.cnblogs.com/dc10101/archive/20 ...
- eclipse导出doc文档
选中需要导出的项目, 1 点击eclipse上面的Project,选择Generate javadoc..., 2 然后配置 javadoc command,比如我本地的路径为: C:\Program ...