题目大意:

求L的最大值

思路:

可以想象出是一个关于人到灯泡距离x的单峰上凸函数

当光线在墙角左边的时候影子在不断增长

然后通过相似可以推出人在墙上影子的长度为:H+D*(h-H)/x

再加上地上的D-x就可以计算出每个x的函数值了

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define inf 2139062143
#define ll long long
#define MAXN 1001000
#define eps 1e-4
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
return x*f;
}
double H,h,d;
double calc(double x){return H+(h*d-H*d)/x+d-x;}
int main()
{
int T=read();
while(T--)
{
scanf("%lf%lf%lf",&H,&h,&d);
double r=d,l=d-h*d/H,ml,mr;
while(r-l>eps)
{
ml=(r-l)/3.0+l,mr=*(r-l)/3.0+l;
if(calc(ml)>calc(mr)) r=mr;
else l=ml;
}
printf("%.3lf\n",calc(r));
}
}

zoj 3023 Light Bulb的更多相关文章

  1. ZOJ 3203 Light Bulb (三分+计算几何)

    B - Light Bulb Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  2. 三分 --- ZOJ 3203 Light Bulb

    Light Bulb Problem's Link:   http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...

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

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

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

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

  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

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

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

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

  8. [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)

    Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...

  9. ZOJ 3203 Light Bulb( 三分求极值 )

    链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...

随机推荐

  1. HashMap、ConcurrentHashMap以及HashTable(面试向)

    ---->HashMap 在java1.7中,hashmap的数据结构是基于数组+链表的结构,即我们比较熟悉的Entry数组,其包含的(key-value)键值对的形式.在多线程环境下,Hash ...

  2. pxc集群安装

    一.pxc镜像url:https://hub.docker.com/r/percona/percona-xtradb-cluster/ 二.安装及重命名: 1.安装:docker pull perco ...

  3. 树莓派 -- 按键 (key)使用BCM2835 gpio library

    BCM2835 GPIO library介绍 This is a C library for Raspberry Pi (RPi). It provides access to GPIO and ot ...

  4. JS 去除字符串空格

    $.trim()是jQuery提供的函数,用于去掉字符串首尾的空白字符. "abc 123 def".replace(/\s/g, "") 去除所有的空格

  5. 【扫描线】HDU 5124 lines

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 [题意] 在数轴x上,每次操作都覆盖一个区间的所有点,问被覆盖次数最多的点是覆盖了多少次 [思路] 最简单 ...

  6. hdu 4435 bfs+贪心

    /* 题意:给定每个点在平面内的坐标,要求选出一些点,在这些点建立加油站,使得总花费最少(1号点必须建立加油站).在i点建立加油站需要花费2^i. 建立加油站要求能使得汽车从1点开始走遍全图所有的点并 ...

  7. poj 1456

    #include<stdio.h> #include<string.h> #include<stdlib.h> #define N 10010 #define in ...

  8. bzoj 1430 小猴打架 prufer 性质

    小猴打架 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 709  Solved: 512[Submit][Status][Discuss] Descri ...

  9. 网络编程基础:粘包现象、基于UDP协议的套接字

    粘包现象: 如上篇博客中最后的示例,客户端有个 phone.recv(2014) , 当服务端发送给客户端的数据大于1024个字节时, 多于1024的数据就会残留在管道中,下次客户端再给服务端发命令时 ...

  10. Linux下汇编语言学习笔记37 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...