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 ...
随机推荐
- sql修改字段值
update dfw_USER_ACCOUNTS set USER_INTEGRAL="20" where USER_INTEGRAL="17"
- 【JavaScript框架封装】实现一个类似于JQuery的缓存框架的封装
// 缓存框架 (function (xframe) { /** * 实现了缓存框架的临时存储功能(内存存储) * @type {{data: Array, get: (function(*): *) ...
- WEBGL学习【十二】鼠标操作场景
<!DOCTYPE HTML> <html lang="en"> <head> <title>Listing 7-3 and 7-4 ...
- Python 安装 numpy 以及 matplotlib 的过程
系统:ubuntu 16.04 版本:Python3.5 步骤: 安装 pip sudo apt install python3-pip 查看 pip list 是否有 numpy 以及 matplo ...
- Project Euler 8 Largest product in a series
题意:寻找这 1000 个数中相邻 13 个数相乘积最大的值 思路:首先想到的是暴力,但是还可以利用之前记录过的数值,什么意思呢?即在计算 2 - 14 后,再计算 3 - 15 时完全可以利用之前计 ...
- [CodeForces]786B Legacy
线段树优化建图. 建立两棵线段树,其上点的点权分别表示"到达这个区间内所有点的最小花费"和"到达这个区间内任意一个点的最小花费". 对于第一种路直接加边即可 对 ...
- js:Array对象常用方法介绍
前言 在js中,数组作为一个特殊的对象.是我们常用的数据格式.今天就来梳理一下常用的数组方法. 1.基础 几种基础的就简单介绍一下:创建数组 var arr1 = new Array(); //括号可 ...
- Java生成随机数的三种方式
package cn.zytao.taosir.random; import java.util.Random; public class RandomDemo { private static In ...
- FFMPEG 音频转换命令
音频转换: .转换amr到mp3: ffmpeg -i shenhuxi.amr amr2mp3.mp3 .转换amr到wav: ffmpeg -acodec libamr_nb -i shenhux ...
- BA-DDC与PLC的比较(转载)
1.概念 DDC(Direct Digital Control ) ,根据字面的意思为直接的数据控制,它包含了对采集数据的数字化以及对数据的数字处理.DDC的产生式随着楼宇控制.能源管理的需求,以及为 ...