ZOJ - 3203 Light Bulb(三分)
题意:灯离地面的高度为$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(三分)的更多相关文章
- ZOJ 3203 Light Bulb (三分+计算几何)
B - Light Bulb Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 三分 --- ZOJ 3203 Light Bulb
Light Bulb Problem's Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...
- ZOJ 3203 Light Bulb (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- 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
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...
- ZOJ 3203 Light Bulb(数学对勾函数)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)
Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...
- ZOJ 3203 Light Bulb( 三分求极值 )
链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...
随机推荐
- EF工作流程
1.EF基本的CRUD(增删改查)流程 2.EF的工作过程简析 EDM--Entity Data Model--实体数据模型 概念模型: EF通过领域类,上下文类,默认约定和配置构建概念模型. 存储模 ...
- linux下部署Mono oracle配置,oracle客户端安装
一.Mono,apache安装,配置网站(以 centos 7 +apache 2为例): 安装教程以官网的教程为追,百度来的多少有版本问题. mono官网连接: 1. Mono的安装:https:/ ...
- Lombok(浅看,自用)
Lombok 首先是几个常用的注解(最常用到的方法,超简单的用) @Data @AllArgsConstructor @NoArgsConstructor public class Trial_Pro ...
- 用eclipse的同一个tomcat启动两个javaweb项目
1.右键选择 Add and Remove 2.把左边两个项目add到右边 3.完成之后查看eclipse左边的Servers下的server.xml文件,会自动生成两个Context标签,当然你到第 ...
- mysql(3):锁和事务
MySQL锁的介绍 锁是数据库系统区别于文件系统的一个关键特性.锁机制用于管理对共享资源的并发访问. 表级锁 例如MyISAM引擎,其锁是表锁设计.并发情况下的读没有问题,但是并发插入时的性能要差一些 ...
- Wx-mpvue开发小程序
一.准备 安装Node 安装vue-cli ( npm install --global vue-cli ) 二.创建 初始化项目 ( vue init mpvue/mpvue-quickstart ...
- angular清空node_modules
安装全局包 npm install rimraf -g 执行清空命令 rimraf node_modules
- kali 安装与配置
打开虚拟机 新建一个虚拟机 导入虚拟文件 然后进行下面的步骤 开启虚拟机 语言:中文简体 地区: 中国 语言: 汉语 自动安装 配置网络 配置域名 填写密码(两次一致) 自动校对时钟 使用整个磁盘 选 ...
- hadoop fs -put could only be replicated to 0 nodes, instead of 1 解决方法
我的坏境是在虚拟机linux操作系统中,启动start-all.sh后 1.执行jps,如下 2.执行hadoop fs -mkdir input 创建成功 执行hadoop fs -ls 可以看到i ...
- linux shell ansible 命令详解
也可以参考ansible 模块介绍的其他文章:https://www.cnblogs.com/guxiaobei/p/8316903.html 安装ansible yum install epel-r ...