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

题意: 求影子长度 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. node中exports和module.exports的关系及使用

    在node中,需要记住,在使用exports和module.exports的时候,实际输出的是module.exports. exports指向module.exports,是module.expor ...

  2. HDU2035 - 人见人爱A^B

    求A^B的最后三位数表示的整数.  说明:A^B的含义是"A的B次方" Input 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=1 ...

  3. codevs——T2102 石子归并 2

     http://codevs.cn/problem/2102/  时间限制: 10 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Des ...

  4. 纯js编写验证信息提示正则匹配数字,字母,空值

    1.显示效果 2,html结构 <div class="border_bg"> <div id="upcCode" style="p ...

  5. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第3章节--SharePoint 2013 开发者工具 用SPD开发SharePoint应用程序

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第3章节--SharePoint 2013 开发者工具 用SPD开发SharePoint应用程序         非常多开 ...

  6. 小P寻宝记——好基友一起走

    小P寻宝记--好基友一起走 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 话说.上次小P到伊利哇呀国旅行得到了一批宝藏.他是 ...

  7. 浏览器启动不起来java.lang.NoClassDefFoundError: com/google/common/base/Function

    java.lang.NoClassDefFoundError: com/google/common/base/Function 原因:只有以下两个包 解决方案:导入 selenium-server-s ...

  8. UVA 11542 Square 高斯消元 异或方程组求解

    题目链接:点击打开链接 白书的例题练练手. . . P161 #include <cstdio> #include <iostream> #include <algori ...

  9. Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 189......

    Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query ...

  10. C9---include,编译

    //main.c //include基本概念 //include是预处理指令,翻译之前会替换,编译之前左的处理,#都是预处理指令,翻译时候会添加别的内容进来. #include <stdio.h ...