灯泡

枚举人到墙的距离\(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;
}

转载于:https://www.cnblogs.com/Maktub-blog/p/11373564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值