题意:灯离地面的高度为$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. python3 读取串口数据

    python3 读取串口数据 demo import serial import time ser = serial.Serial("COM3",115200,timeout = ...

  2. linux交互执行命令,expect

    转载 http://donex.blog.51cto.com/2005970/834467 原文比较乱,只能参考 本地交互执行: 1. 修改shell#!/usr/bin/expectset USER ...

  3. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  4. 解决ERROR 1130: Host 'x.x.x.x' is not allowed to connect to this MariaDB server 方法

    问题描述 在使用SQLyog操作Linux上的MariaDB时候,会出现如下错误: 解决方法 改表法 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电 ...

  5. axios中then不用第二个参数,最好用catch

    一般来说,不要在then方法里面定义 Reject 状态的回调函数(即then的第二个参数),总是使用catch方法. // bad promise .then(function(data) { // ...

  6. JS中使用lambda筛选list

    LevelEnum.filter(x=>x.Category=="水利工程")

  7. 环境配置 | Pycharm远程开发的环境配置

    目的:同局域网中的两台电脑,Mac上看视频学习编程 + 当服务器跑代码:Windows上使用Pycharm写代码.学习远程开发 (当前底子有限,很多操作可能存在理解偏差) Mac上代码存放路径:~/O ...

  8. vue 文件插件 Vetur 设置说明官网

    vue 文件插件 Vetur 设置说明官网 https://vuejs.github.io/vetur/formatting.html#settings

  9. C#中数据类型char*,const char*和string的三者转换

    C#中数据类型char*,const char*和string的三者转换: . const char* 和string 转换 () const char*转换为 string,直接赋值即可. EX: ...

  10. apache+SSL 搭建https

    简单介绍 一般情况下,我们打开网站默认的是使用明文传输方式,但在日常生活中,当我们在登录或者支付交易时,网站就会自动跳转至SSL(Secure Sockets Layes)加密传输模式,SSL的功能就 ...