题目大意:

求L的最大值

思路:

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

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

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

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

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<vector>
  8. #include<queue>
  9. #define inf 2139062143
  10. #define ll long long
  11. #define MAXN 1001000
  12. #define eps 1e-4
  13. using namespace std;
  14. inline int read()
  15. {
  16. int x=,f=;char ch=getchar();
  17. while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
  18. while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
  19. return x*f;
  20. }
  21. double H,h,d;
  22. double calc(double x){return H+(h*d-H*d)/x+d-x;}
  23. int main()
  24. {
  25. int T=read();
  26. while(T--)
  27. {
  28. scanf("%lf%lf%lf",&H,&h,&d);
  29. double r=d,l=d-h*d/H,ml,mr;
  30. while(r-l>eps)
  31. {
  32. ml=(r-l)/3.0+l,mr=*(r-l)/3.0+l;
  33. if(calc(ml)>calc(mr)) r=mr;
  34. else l=ml;
  35. }
  36. printf("%.3lf\n",calc(r));
  37. }
  38. }

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. Sql语句的一些事(二)

    与sql语句的书写顺序并不是一样的,而是按照下面的顺序来执行 from--where--group by--having--select--order by, from:需要从哪个数据表检索数据 wh ...

  2. 合办大学 -- internal campus in China

    * 合办大学 -- internal campus in China- international campus zhejiang University- 南方科技大学 - 西交利物浦大学(Xi’an ...

  3. ICE CAVE(BFS搜索(模拟))

    Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...

  4. UVA 213 信息解码(二进制&位运算)

    题意: 出自刘汝佳算法竞赛入门经典第四章. 考虑下面的01串序列: 0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, …, 1 ...

  5. 九度oj 题目1182:统计单词

    题目1182:统计单词 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4780 解决:1764 题目描述: 编一个程序,读入用户输入的,以“.”结尾的一行文字,统计一共有多少个单词,并分别 ...

  6. uva10537 最短路 倒推

    题意:知道了,最后需要的,那么就倒着最短路,推出去就可以了. 以最短路的方式来解决.

  7. Python模块:logging、

    logging模块: 很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出.Python的logging模块提供了标准的日志接口,你可以通过它存储各种格 ...

  8. 主席树初探--BZOJ1901: Zju2112 Dynamic Rankings

    n<=10000的序列做m<=10000个操作:单点修改,查区间第k小. 所谓的主席树也就是一个值域线段树嘛..不过在这里还是%%fotile 需要做一个区间查询,由于查第k小,需要一些能 ...

  9. Our Journey of Dalian Ends 乌鲁木齐网络赛 最小费用最大流

    Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpecte ...

  10. hdu4701 Game(递推博弈)

    题意: Alice初始有A元,Bob有B元. 有N个物品,第i个物品价值为Ci.Alice和Bob轮流买一些(>=1)物品.不能移动的人输.购买有一个限制,对于第1 个之后物品,只有当第i-1个 ...