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 ...
随机推荐
- 跪求 EF缓存问题 也不知道是不是缓存 问题
1.数据库里面查的结果 2 vs里面查的结果 为什么 不是16 而是2 下面是代码 /// <summary> /// 权限检查 /// </summary> public ...
- 使用Calendar增加日期
/** * @Description: 当前日期加上n个月返回long date */ public static long getLongDateAddMonth(int n){ Calendar ...
- 创业不要在IT业内创(市场太小,而且都喜欢自己折腾、没有花钱的习惯)
精神是好的.但是,我看了你的产品和网站:你选的创业方向基本是死路一条,我劝你该放弃就放弃.我判断你的思路还局限在IT行业内,创业不要在IT业内创,要走出去,睁开眼看看别人的世界,自己体会.我不是打击你 ...
- jQuery之Jcrop
头像裁剪是一个经常用到的功能,实现原理也较为简单,就是在本地选择好所需裁剪图片的坐标,将坐标发送到服务器,由服务器执行图片裁剪操作. jQuery插件Jcrop提供了强大的图片裁剪坐标选择插件.一下来 ...
- ArcGIS for WPF 访问外部资源【进阶之构造URL】
原文 http://www.cnblogs.com/wdysunflower/archive/2013/05/29/3039645.html 呵呵~好久没逛园子,没写博客了. 最近刚好又在弄GIS这块 ...
- UVA 11111-Generalized Matrioshkas(栈)
题意:有很多层盒子,盒子里面再套盒子,一个盒子可能套多个独立的子盒子,但子盒子的总体积必须小于该盒子,否则不合法,输入给一行数,负数代表左边,正数代表右边,大小表示其体积,如-2,-1,1,2则表示体 ...
- 【POJ 2010 Moo University-Financial Aid】优先级队列
题目链接:http://poj.org/problem?id=2010 题意:C只牛犊,各有自己的分数score和申请的补助aid,现要选出N只(N为奇数),使得其aid的总和不超过F,且按score ...
- IOS拷贝文件到沙盒
- (void)copyFileFromResourceTOSandbox { //文件类型 NSString * docPath = [[NSBundle mainBundle] pathForRe ...
- IsDbNull 方法的用法
本文来自:http://lazhgg.cnblogs.com/archive/2006/02/21/334915.html 在c#中,进行数据库查询时使用IsDbNull 方法判断数据库中字段值是否存 ...
- STL之nth_element()(取容器中的第n大值)
nth_element()函数 头文件:#include<algorithm> 作用:nth_element作用为求第n大的元素,并把它放在第n位置上,下标是从0開始计数的,也就是说求第0 ...