**链接:****传送门 **

题意: 求影子长度 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( 三分求极值 )的更多相关文章

  1. ZOJ - 3203 Light Bulb(三分)

    题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...

  2. ZOJ 3203 Light Bulb (三分+计算几何)

    B - Light Bulb Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  3. 三分 --- ZOJ 3203 Light Bulb

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

  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,三分之二的基本问题

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

  7. ZOJ 3203 Light Bulb

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

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

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

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

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

随机推荐

  1. GDI 线段绘制示例程序

    #include <windows.h> #include <strsafe.h> #include <stack> typedef struct tagLINE ...

  2. N1-1 - 树 - Minimum Depth of Binary Tree

    题目描述: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the ...

  3. 【Computer Vision】 复现分割网络(1)——SegNet

    目录 Tags: ComputerVision 编译 数据处理 训练结果 Reference Tags: ComputerVision 编译 src/caffe/layers/contrastive_ ...

  4. CSS3 创建简单的网页动画 – 实现弹跳球动

    基础准备对于这个实现,我们需要一个简单的 div ,并且样式类名为 ball : HTML 代码: <div class="ball"></div> 我们将 ...

  5. Problem 4

    Problem 4 # Problem_4 """ A palindromic number reads the same both ways. The largest ...

  6. ConcurrentHashMap 并发HashMap原理分析

        ConcurrentHashMap和Hashtable主要区别就是围绕着锁的粒度以及如何锁.如图   左边便是Hashtable的实现方式---锁整个hash表:而右边则是Concurrent ...

  7. deep learning 经典网络模型之Alexnet、VGG、Googlenet、Resnet

    CNN的发展史 上一篇回顾讲的是2006年Hinton他们的Science Paper,当时提到,2006年虽然Deep Learning的概念被提出来了,但是学术界的大家还是表示不服.当时有流传的段 ...

  8. LaTeX soul包

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50774955 详细的soul包的官方P ...

  9. 零基础学python-7.7 字符串格式化方法(1)

    承接上一章节.我们这一节来说说字符串格式化的还有一种方法.就是调用format() >>> template='{0},{1} and {2}' >>> templ ...

  10. nyoj--118--修路方案(次小生成树)

    修路方案 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述 南将军率领着许多部队,它们分别驻扎在N个不同的城市里,这些城市分别编号1~N,由于交通不太便利,南将军准备修路. ...