【三分】light bulb(zoj3203)
题目描述:
如图,你可以在房间里移动,灯泡的高度为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)的更多相关文章
- Light Bulb(三分)
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildl ...
- 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 (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- A. Light Bulb
A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO f ...
- 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
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 ...
- TOJ 2814 Light Bulb
Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house ...
随机推荐
- bootstrap学习-初步使用介绍
准备 下载Bootstrap https://github.com/twbs/bootstrap/releases/download/v3.3.6/bootstrap-3.3.6-dist.zip h ...
- Android Things:撸起袖子来创建第一个Things工程
http://blog.csdn.net/p106786860/article/details/60161020 ——————————————————————————————————————————— ...
- 关于Unity中ARPG游戏人物移动(专题十一)
ARPG:动作型角色扮演类游戏 大多数的ARPG游戏都是使用摇杆操作,以第三人称摄像机的方式来跟随主角,实际上人物只走八个方向,上,下,左,右,左上,左下,右下,右上 控制角色移动的思路1: 在ARP ...
- apk MIME类型
MIME (Multipurpose Internet Mail Extensions) 多用途互联网邮件扩展,它设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- centos7 网络配置
vi /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPR ...
- IOC容器特性注入第四篇:容器初始化
IOC容器,就是把各种服务都注入到容器里,想要什么就去拿什么,不仅解决服务类和接口类的耦合度还可以提高性能方便管理. 这里封装一个接口类和一个实现类 1.IContainerManager接口 pub ...
- 网络编程 -- RPC实现原理 -- Netty -- 迭代版本V2 -- 对象传输
网络编程 -- RPC实现原理 -- 目录 啦啦啦 V2——Netty -- 使用序列化和反序列化在网络上传输对象:需要实现 java.io.Serializable 接口 只能传输( ByteBuf ...
- 【typecho】解决使用分隔符 <!--more-->标签后首页文字下面出现一段空白
使用typecho 搭建了一个站点,输出摘要时候.使用了 <!--more--> 分隔符,然后首页文章出现了一大片空白,审查元素发现.多了好多 <br> 标签 解决办法: ...
- libuv示例代码
https://github.com/nikhilm/uvbook/tree/master/code
- javascript定时器使用
使用定时器实现JavaScript的延期执行或重复执行 window对象提供了两个方法来实现定时器的效果,分别是window.setTimeout()和window.setInterval.其中前者可 ...