【三分】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 ...
随机推荐
- 【转载】VC维,结构风险最小化
以下文章转载自http://blog.sina.com.cn/s/blog_7103b28a0102w9tr.html 如有侵权,请留言,立即删除. 1 VC维的描述和理解 给定一个集合S={x1,x ...
- Git错误:error: The following untracked working tree files would be overwritten by merge:
[andy@localhost weixin_robot]$ git pull Updating d652d1c..fa05549 error: The following untracked wor ...
- linux dns 工具包 -- bind-utils
https://www.cnblogs.com/274914765qq/p/4817941.html
- python concurrent.futures.Threadpoolexcutor的有界队列和无界队列
1.默认是无界队列,如果生产任务的速度大大超过消费的速度,则会把生产任务无限添加到无界队列中,这样一来控制不了生产速度,二来是会造成系统内存会被队列中的元素堆积增多而耗尽. 2.改写为有界队列 cla ...
- [hadoop] hadoop 运行 wordcount
讲准备好的文本文件放到hdfs中 执行 hadoop 安装包中的例子 [root@hadoop01 mapreduce]# hadoop jar hadoop-mapreduce-examples-2 ...
- [Bayes] Multinomials and Dirichlet distribution
From: https://www.cs.cmu.edu/~scohen/psnlp-lecture6.pdf 不错的PPT,图示很好. 伯努利分布 和 多项式分布 Binomial Distribu ...
- [Python] 00 - Books
A.I. & Optimization Advanced Machine Learning, Data Mining, and Online Advertising Services Ref: ...
- [Android] 基于 Linux 命令行构建 Android 应用(四):命令行构建
谷歌提供的 Android SDK 支持 Ant 自动构建[1],你可以使用调试和发行两种模式进行构建,两种模式不同之处在于调试模式 Ant 会调用内置的调试密钥,而发行模式调用你提供的私钥. 首先安 ...
- MySQL 去除字段中的换行和回车符
今天csv 导入关键词的时候遇到问题 字段结束会有 回车符号 解决方法: ), ),''); char(10): 换行符 char(13): 回车符
- Android Selinux
https://blog.csdn.net/rikeyone/article/details/84337115 如何快速定位SElinux问题并修复? https://blog.csdn.net/ ...