灯泡

枚举人到墙的距离\(x\), 根据初中的三角形相似知识很容易推出计算式, 需要注意的是这个计算式有一定范围, 必须要把影子投到墙上, 显然如果不投到墙上, \(x\)越大影长越小。

总影长大致是先增后减的, 证明应该是可以推出个二次函数的式子。。。懒得推了, 直接三分便可以。。

关键是边界。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<cmath>
#include<cstdlib>
#include<ctime>

using namespace std;

#define FOR(a, b, c) for(int a = b; a <= c; a++)

const int mx = 1e5 + 5;
const int inf = 1<<30;

void fre() {
    freopen(".txt", "r", stdin);
    freopen(".txt", "w", stdout);
}

double H, h, D;

double calc(double x) {
//  if(x == D) return 0;
//  if(h <= x*r) return (h/r);
    return (h-x*(H-h)/(D-x))+x;
}

int main(){
    //fre();
    int t; cin >> t;
    while(t--) {
        cin >> H >> h >> D;
        double l = 0, r = D*h/H;
        while(r - l > 0.000001) {
            double lmid = l+(r-l)/3, rmid = r-(r-l)/3;
            if(calc(lmid) <= calc(rmid)) l = lmid;
            else r = rmid; 
        }
        printf("%.3lf\n", calc(l));
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Maktub-blog/p/11373564.html