题目描述:

如图,你可以在房间里移动,灯泡的高度为H,你的身高为h,灯泡与墙的水平距离为D,求你影子的最长长度(影子长度=地上影子长度+墙上影子长度)

样例输入:

  0.5
0.5

样例输出:

1.000

0.750

4.000

此题是一道三分模板题

用x表示墙上影子的长度,根据相似三角形可以得到地上的影子长度为(h-x)*d/(H-x)

如图:

三分答案求x即可

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; inline int read()
{
int f=,x=;
char ch=getchar();
while(ch<'' || ch>'') {if(ch=='-') f=-; ch=getchar();}
while(ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
} int T;
double H,h,d; double f(double x)
{
return (h-x)*d/(H-x)+x;
} int main()
{
T=read();
while(T--)
{
scanf("%lf%lf%lf",&H,&h,&d);
double l=,r=h;
while(r-l>1e-)
{
double lm=l+(r-l)/,rm=r-(r-l)/;
if(f(lm)>=f(rm)) r=rm;
else l=lm;
}
printf("%.3lf\n",f(r));
}
return ;
}

这是代码

【三分】light bulb(zoj3203)的更多相关文章

  1. Light Bulb(三分)

    ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildl ...

  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 (三分查找)

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

  5. A. Light Bulb

    A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB   64-bit integer IO f ...

  6. ZOJ 3203 Light Bulb - 求导求最大值

    如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...

  7. zoj 3203 Light Bulb,三分之二的基本问题

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

  8. ZOJ 3203 Light Bulb

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

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

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

  10. TOJ 2814 Light Bulb

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

随机推荐

  1. TI开发环境下载资源

    CCSV7.0 版本下载  http://processors.wiki.ti.com/index.php/Download_CCS IAR7.10 版本下载 https://www.iar.com/ ...

  2. php memcached 扩展

    php_memcache.dll下载地址:http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/ 查看php线程:phpinfo ...

  3. duilib进阶教程 -- Label控件的bug (8)

    上个教程说到了TreeView的文字不能垂直居中的问题,而我们用LabelUI其实是可以垂直居中的,为什么不说是TreeView的bug,而说是Label控件的bug呢?因为影响TreeView垂直居 ...

  4. Golang中下划线的使用

    https://studygolang.com/articles/17479?fr=sidebar

  5. Java -- POI -- 随笔汇总

    1. 判断指定的单元格是否是合并单元格 /** * 功能:判断指定的单元格是否是合并单元格 * 原理:excel中的合并单元格其实就是首单元格,只不过该单元格增加了 rowspan和colspan两个 ...

  6. cocos2d-x游戏引擎核心(3.x)----事件分发机制之事件从(android,ios,desktop)系统传到cocos2dx的过程浅析

    (一) Android平台下: cocos2dx 版本3.2,先导入一个android工程,然后看下AndroidManifest.xml <application android:label= ...

  7. TestLink汉化操作

    实验环境版本 xampp-windows-x64-7.3.2-0-VC15-installer + testlink-1.9.19 汉化操作如下 打开testlink的配置文件F:\xampp\htd ...

  8. CSS3 水平翻转

    .button_1:hover #button1_img,.button_2:hover #button2_img{ box-shadow: 0 0 10px #9AFE2E; animation: ...

  9. MFC打开文件选择框和多选框,保存文件夹的选择,保存文件路径的选择

    CString defaultDir = "C:\\"; //默认打开的文件路径 CString fileName = ""; //默认打开的文件名 CStri ...

  10. 带分数|2013年蓝桥杯B组题解析第九题-fishers

    带分数 100 可以表示为带分数的形式:100 = 3 + 69258 / 714 还可以表示为:100 = 82 + 3546 / 197 注意特征:带分数中,数字1~9分别出现且只出现一次(不包含 ...