ZOJ Problem Set - 3203
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>
int main(){
int T;
double H,h,D;
//公式:D-x+H-(H-h)*D/x;
//求导:-1+(H-h)*D/(x*x)
//导数等于0,求得极值x=sqrt((H-h)*D)
//影子在地面最长时x=(H-h)*D/H;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf",&H,&h,&D);
double jz=sqrt((H-h)*D);
double ans;
if(jz<=(H-h)*D/H)ans=D-(H-h)*D/H;
else if(jz>=D)ans=h;
else ans=D-jz+H-(H-h)*D/jz;
printf("%.3lf\n",ans);
}
return ;
}

三分:

 #include<stdio.h>
#include<math.h>
double H,h,D;
double getl(double x){
return D-x+H-(H-h)*D/x;
}
void sanfen(){
double l=(H-h)*D/H,m,mm,r=D;//l从地面最长开始
while(r-l>1e-){
m=(l+r)/;
mm=(m+r)/;
if(getl(m)>=getl(mm))r=mm;
else l=m;
}
printf("%.3lf\n",getl(l));
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf",&H,&h,&D);
sanfen();
}
return ;
}

Light Bulb(三分)的更多相关文章

  1. ZOJ 3203 Light Bulb (三分+计算几何)

    B - Light Bulb Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  2. ZOJ - 3203 Light Bulb(三分)

    题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...

  3. 三分 --- ZOJ 3203 Light Bulb

    Light Bulb Problem's Link:   http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...

  4. ZOJ 3203 Light Bulb (三分查找)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  5. A. Light Bulb

    A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB   64-bit integer IO f ...

  6. ZOJ 3203 Light Bulb - 求导求最大值

    如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...

  7. zoj 3203 Light Bulb,三分之二的基本问题

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  8. ZOJ 3203 Light Bulb

    Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...

  9. ZOJ 3203 Light Bulb(数学对勾函数)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

随机推荐

  1. js屏蔽浏览器(IE和FireFox)的刷新和右键等功能

    //一.js屏蔽浏览器(IE和FireFox)的刷新功能 document.onkeydown=function() { if ((window.event.keyCode==116)|| //屏蔽 ...

  2. Arduino当avr开发板

    原理并不复杂,因为arduino本来就是avr+一堆的库,找个能编译出hex的工具下载到板子就行. 但实际做起来还是碰到很多问题. 先是尝试eclipse+avr plugin 编译时出现make: ...

  3. 走进C标准库(3)——"stdio.h"中的getc和ungetc

    接前文. 再来看看getc和ungetc的实现.在看这两个函数的实现之前,我们先来想一想这两个函数分别需要做的工作. int getc(FILE *stream) 说明:函数getc从stream指向 ...

  4. kvm中运行kvm

    如何在 KVM 虚拟机上运行 KVM 上次讨论了如何在 VMware ESXi 虚拟机上运行 KVM 问题,前不久有读者想 “在 kvm 上面创建个虚拟机安装 rackspace 的 openstac ...

  5. Numpy之ndarray与matrix

    1. ndarray对象 ndarray是numpy中的一个N维数组对象,可以进行矢量算术运算,它是一个通用的同构数据多维容器,即其中的所有元素必须是相同类型的. 可以使用array函数创建数组,每个 ...

  6. 初探swift语言的学习笔记(闭包 - 匿名函数或block块代码)

    很多高级语言都支持匿名函数操作,在OC中的block也为大家所熟悉,然面在swift里好像是被重新作了一个定义,不叫匿名函数,或 block了,而叫闭包(closure).下面配合代码来理解一下swi ...

  7. Android 读取Assets中图片

    bgimg0 = getImageFromAssetsFile("Cat_Blink/cat_blink0000.png"); * * 从Assets中读取图片 */ privat ...

  8. ASP.NET导出EXCEl方法使用COM.EXCEL不使用EXCEl对象

    第一种:导出gridVIEW中的数据,用hansTABLE做离线表,将数据库中指定表中的所有数据按GRIDVIEW中绑定的ID导出 只能导出数据不能去操作相应的EXCEl表格,不能对EXCEL中的数据 ...

  9. web开发 - 从零开始 - 03 - 选择器

    行间样式>id>class>类型选择>通配符 选择器的优先级一致的情况下,后边的样式会覆盖前边的

  10. 腾讯TGideas语义化标签(转)

    --------引子--------------- 家里有个熊孩子,经常会有一些意想不到的事情发生:回家的时候,他会笑呵呵冲过来,大声喊着“臭爸爸”:你让他把鞋穿上,他会提起鞋子往楼下扔...在小孩的 ...