Light Bulb 三分入门题

                      Light Bulb

分析:求出公式,发现在给定范围内是凸函数。三分求最值。

 1 /********************************
 2 please don't hack me!! /(ToT)/~~
 3                 __------__
 4               /~          ~\
 5              |    //^\\//^\|
 6            /~~\  ||  T| |T|:~\
 7           | |6   ||___|_|_||:|
 8            \__.  /      o  \/'
 9             |   (       O   )
10    /~~~~\    `\  \         /
11   | |~~\ |     )  ~------~`\
12  /' |  | |   /     ____ /~~~)\
13 (_/'   | | |     /'    |    ( |
14        | | |     \    /   __)/ \
15        \  \ \      \/    /' \   `\
16          \  \|\        /   | |\___|
17            \ |  \____/     | |
18            /^~>  \        _/ <
19           |  |         \       \
20           |  | \        \        \
21           -^-\  \       |        )
22                `\_______/^\______/
23 ************************************/
24 
25 #include <iostream>
26 #include <cstdio>
27 #include <cstring>
28 #include <cmath>
29 #include <algorithm>
30 #include <string>
31 #include <vector>
32 #include <set>
33 #include <map>
34 #include <queue>
35 #include <stack>
36 #include <cstdlib>
37 #include <sstream>
38 using namespace std;
39 typedef long long LL;
40 const LL INF = 0x5fffffff;
41 const double EXP = 1E-8;
42 const LL MOD = (LL)1E9+7;
43 const int MS = 1005;
44 
45 double H, h, D;
46 
47 double fun(double x) {
48     return (h - H) * D / (D - x) + H + x;
49 }
50 
51 int main() {
52     int T;
53     scanf("%d",&T);
54     while (T--) {
55         scanf("%lf%lf%lf",&H,&h,&D);
56         double l = 0;
57         double r = h * D / H;
58         while ((r - l) >= EXP) {
59             double mid = (l + r) / 2;
60             double mmid = (mid + r) / 2;
61             if (fun(mid) > fun(mmid))
62                 r = mmid;
63             else
64                 l = mid;
65         }
66         printf("%.3lf\n",fun(l));
67     }
68     return 0;
69 }

 

转载于:https://www.cnblogs.com/hutaishi/p/4735004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值