Light Bulb--zoj3203(三分法)
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
#include<stdio.h>
#include<math.h>
double hs(double H,double h,double D,double X)
{
return D*(h-X)/(H-X)+X;//定义求长度的函数,这里的X是人在墙上的投影长度
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
double mid,midmid,l=,r=b;
do
{
mid=(l+r)/;
midmid=(mid+r)/;
if(hs(a,b,c,mid)>hs(a,b,c,midmid))
r=midmid;
else
l=mid;
}while(r-l>1e-);
printf("%.3lf\n",hs(a,b,c,mid));
}
return ;
}
主要的思想是三分法求函数的最大值,不过要注意精度我精确到1e-6都wa了,也是醉了!
建议以后都要精确到1e-9!
Light Bulb--zoj3203(三分法)的更多相关文章
- ZOJ 3203 Light Bulb (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- TOJ 2814 Light Bulb
Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house ...
- A. Light Bulb
A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO f ...
- [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)
Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...
- 三分 --- 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
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...
随机推荐
- 本部校赛 蛇形填数(二)problen1338
Description 萌萌哒cy学姐参加去年的新生杯的时候,蛇形矩阵那题被她分分钟秒掉,于是她决定出一个更难的题目,她要求矩阵里的每个数都是质数,当然,蛇形的规则也略有变化 如2*3矩阵: 2 7 ...
- 场景2 nginx 错误日志格式:
nginx 错误日志格式: 2016/09/01 11:23:36 [error] 28388#0: *14549 open() "/var/www/zjzc-web-frontEnd/im ...
- mosquitto在Linux环境下的部署/安装/使用/测试
mosquitto在Linux环境下的部署 看了有三四天的的源码,(当然没怎么好好看了),突然发现对mosquitto的源码有了一点点感觉,于是在第五天决定在Linux环境下部署mosquitto. ...
- 中国版 Ubuntu Kylin 14.04 LTS 麒麟操作系统中文版发布下载 (Ubuntu天朝定制版)
中国版 Ubuntu Kylin 14.04 LTS 麒麟操作系统中文版发布下载 (Ubuntu天朝定制版) http://www.iplaysoft.com/ubuntukylin.html
- LintCode-A + B 用位操作模拟加法
class Solution { public: /* * @param a: The first integer * @param b: The second integer * @return: ...
- poj 1703(带权并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31840 Accepted: ...
- 类linux系统/proc/sysrq-trigger文件功能作用
立即重启计算机 echo "b" > /proc/sysrq-trigger 立即关闭计算机 echo "o" > /proc/ ...
- C#代码控制 zip rar 解压缩
首先 解压ZIP的方法: #region 解压ZIP /// <summary> /// 解压ZIP /// </summary> /// <param name=&qu ...
- Python 单词字母顺序不变且所有倒排
翻出google測试project师的一道题目: 设计一个函数,不论什么语言都能够,实现下面功能: 一个句子,将句子中的单词所有倒排过来,但单词的字母顺序不变.eg. this is a real ...
- Visual Studio® 2010 Web Deployment Projects站点编译生成bin同时发表插件
VS2010环境下: 1.Visual Studio® 2010 Web Deployment Projects下载地址: http://www.microsoft.com/downlo ...