ZOJ 3203 Light Bulb( 三分求极值 )
**链接:****传送门 **
题意: 求影子长度 L 的最大值

思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况。根据图中的辅助线外加相似三角形定理可以得到 L = D * (h-x)/(H-x) + x , 再经过一些变形后可知这个 L = D * ( H - h )/( x - H ) + ( x - H ) + H + D ,明显的对号函数在左侧的图像,所以一定是个 凸函数 ,用三分求出极值即可
/*************************************************************************
> File Name: zoj3203.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月05日 星期五 18时53分33秒
************************************************************************/
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;
#define eps 1e-6
#define dou double
dou H,h,D;
int T;
dou f(dou x){
return D*(h-x)/(H-x) + x;
}
void solve(){
// 一定要注意边界的选取,不能随意乱选!!
dou l = 0 , r = h , mid , midmid;
while(r-l>eps){
mid = (l+r)/2;
midmid = (mid+r)/2;
if( f(mid)>=f(midmid) ) r = midmid;
else l = mid;
}
dou ans = f((r+l)/2);
// cout<< fixed << setprecision(3) << ans <<endl;
printf("%.3lf\n",ans);
}
int main(){
scanf("%d",&T);
while(T--){
cin>> H >> h >> D;
solve();
}
return 0;
}
ZOJ 3203 Light Bulb( 三分求极值 )的更多相关文章
- ZOJ - 3203 Light Bulb(三分)
题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...
- 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 - 求导求最大值
如果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,三分之二的基本问题
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 ...
随机推荐
- JavaScript学习笔记(第一天)
javascript个人笔记 JavaScript的组成 JavaScript是一种运行在客户端的脚本语言 ECMAScript 标准----js的基本的语法 DOM------Document ...
- Project Euler 26 Reciprocal cycles( 分数循环节 )
题意: 单位分数指分子为1的分数.分母为2至10的单位分数的十进制表示如下所示: 1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6 ...
- 面试准备专题——SOA架构
- CodeForcesGym 100676G Training Camp
G. Training Camp Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...
- Matlab中的函数句柄@
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50699990 @是Matlab中的句柄 ...
- C#中的全局程序集缓存定义
安装有公共语言运行时的每台计算机都具有称为全局程序集缓存的计算机范围内的代码缓存.全局程序集缓存中存储了专门指定给由计算机中若干应用程序共享的程序集. 应当仅在需要时才将程序集安装到全局程序集缓存中以 ...
- [HTML5] Handle Offscreen Accessibility
Sometime when some component is offscreen, but still get focus when we tab though the page. This can ...
- hibernate 管理 Session(单独使用session,非spring)
Hibernate 自身提供了三种管理 Session 对象的方法 Session 对象的生命周期与本地线程绑定 Session 对象的生命周期与 JTA 事务绑定 Hibernate 托付程序管理 ...
- Codeforces Round #260 (Div. 1)——Civilization
题目链接 题意: n个点,m条边的森林.q次操作. 每次操作:1.询问x所在树的直径 2.合并x和y所在的树,使得合并后的直径最小 ) 分析: 没有读到图是森林.. .做的好纠结 最開始将每一个树都求 ...
- OpenST Basic tool library
/***************************************************************************** * OpenST Basic tool l ...