题目描述:

如图,你可以在房间里移动,灯泡的高度为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. talk 1

    话转偏锋 让别人可以接话, 同时可以设计转换到的话题, 把"谈话带到正确的轨道", 就像下象棋一样, 要看三步 A: 很喜欢看篮球比赛, 对B说 我每次都堵湖人队会赢 B: 篮球最 ...

  2. Java如何从服务器获取文件大小?

    在Java编程中,如何从服务器获取文件大小? 以下示例演示如何从服务器获取文件大小. package com.yiibai; import java.net.URL; import java.net. ...

  3. SpringDataJPA - 复杂查询总结 (多表关联 以及 自定义分页 )

    实体类 @Entity @Table(name = "t_hotel") @Data public class THotel { @Id private int id; priva ...

  4. docker_File 执行报错总结

    编写dockerfile [root@linux-node1 ~/dk]# cat Dockerfile # this is a docker File FROM centos MAINTAINER ...

  5. 一种消息和任务队列——beanstalkd

    beanstalkd 是一个轻量级消息中间件,其主要特性: 基于管道  (tube) 和任务 (job) 的工作队列 (work-queue):d 管道(tube),tube类似于消息主题(topic ...

  6. Oracle数据库入门——目录结构

    一.Oracle_Home目录 Oracle_Home主目录位于D:\dev\oracle\product\10.2.0(oracle安装路径)下,它包含Oracle软件运行有关的子目录和网络文件以及 ...

  7. TestLink汉化操作

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

  8. C - Yogurt factory

    The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 &l ...

  9. Page Visibility API 页面是否获取焦点 Event: visibilitychange

    W3C 文档 https://www.w3.org/TR/page-visibility/ MDN 文档 https://www.w3.org/TR/page-visibility/ // Docum ...

  10. ubuntu部署安装 MySQL 5.7

    安装 MySQL 5.7安装 MySQL 运行命令: apt-get -y install mysql-server mysql-client 你会被要求提供MySQL的root用户密码 : New ...