题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度。

思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子消失,此时人再往前走,影子的长度必然会减小,此时的$L$就为三分的左边界,右边界为$R=D$,由形似三角形可以推导出$L=D-\frac{h*D}{H}$,影子的长度

$$f(x)=D-x+H-\frac{(H-h)*D}{x},x\in [D-\frac{h*D}{H},D]$$

在区间$[D-\frac{h*D}{H},D]$三分求极值即可。

#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; const double eps = 1e-; int t;
double H, h, D; double f(double x)
{
return D - x + H - (H - h) * D / x;
} double three_devide(double l, double r)
{
while (r - l > eps) {
double lmid = (l + r) / ;
double rmid = (lmid + r) / ;
if (f(lmid) < f(rmid)) l = lmid;
else r = rmid;
}
return l;
} int main()
{
scanf("%d", &t);
while (t--) {
scanf("%lf%lf%lf", &H, &h, &D);
double res = f(three_devide(D - h * D / H, D));
printf("%.3lf\n", res);
}
return ;
}

记录一下三分的模板:

求单峰函数的极值时,如果$f(lmid)<f(rmid)$,则令$l=lmid$,否则令$r=rmid$

求单谷函数的极值时,如果$f(lmid)>f(rmid)$,则令$l=lmid$,否则令$r=rmid$

ZOJ - 3203 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

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

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

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

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

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

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

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

  6. ZOJ 3203 Light Bulb

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

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

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

  8. [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)

    Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...

  9. ZOJ 3203 Light Bulb( 三分求极值 )

    链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...

随机推荐

  1. IIS7.5 HTTP 错误 500 调用loadlibraryex失败的解决方法

    在IIS7.5打开网页的时候,提示: HTTP 错误 500.0 - Internal Server Error 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 C:\Windows\ ...

  2. TD - setAttribute()

    添加指定的属性,并为其赋指定的值 this.sltLevelType.setAttribute("height", "100px");

  3. webrtc博客收藏

    <使用WebRTC搭建前端视频聊天室——入门篇><使用WebRTC搭建前端视频聊天室——信令篇><使用WebRTC搭建前端视频聊天室——点对点通信篇><使用W ...

  4. UES

    Spring-core-4.3.16 ObjectUtils.java public static boolean isEmpty(Object obj) { if (obj == null) { r ...

  5. 箭头函数 与 forEach

    array.forEach(function(item,index){ }.bind(this)); 同 array.forEach((item,index) =>{ });

  6. C++-POJ1200-Crazy Search[hash]

    由于已经给出字符只有NC种,故可以把子串视为一个NC进制的数,以此构造hash函数就可以了 #include <set> #include <map> #include < ...

  7. Axure 8.1.0.3377 激活码 授权码 (亲测有效)

    适用版本 Axure 8.1.0.3377 zdfans.com gP5uuK2gH+iIVO3YFZwoKyxAdHpXRGNnZWN8Obntqv7++FF3pAz7dTu8B61ySxli 亲测 ...

  8. DataFrames,Datasets,与 SparkSQL

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  9. Django_类视图

    1. View 2. tamplate view 3. ListView

  10. vue 使用 jsonp 请求数据

    vue 使用 jsonp 请求数据 vue请求数据的时候,会遇到跨域问题,服务器为了保证信息的安全,对跨域请求进行拦截,因此,为了解决vue跨域请求问题,需要使用jsonp. 安装jsonp npm ...