• POJ 2507 Crossed ladders


    题目链接:POJ 2507 Crossed ladders

    题目大意:

    题解:
    53

    如图所示,已知(left{egin{aligned}frac{CD}{AB}=frac{DF}{BF}\frac{CD}{EF}=frac{BD}{BF}end{aligned} ight.)
    两式相加得(frac{CD}{AB}+frac{CD}{EF} = 1)
    等式两边同时乘以(AB imes EF)(CD imes (AB + EF) = AB imes EF)
    代入题目中,设两楼之间距离为(d),则可得(c imes (sqrt{x^2 - d^2} + sqrt{y^2 - d^2}) = sqrt{x^2 - d^2} imes sqrt{y^2 - d^2})
    (d)进行二分答案,由于是浮点数所以需要设置二分的次数限制。

    #include <cmath>
    #include <iomanip>
    #include <iostream>
    using namespace std;
    
    double x, y, c;
    
    bool judge(double d) {
        double t1 = sqrt(x * x - d * d);
        double t2 = sqrt(y * y - d * d);
        if (t1 * t2 >= c * (t1 + t2)) {
            return true;
        } else {
            return false;
        }
    }
    
    int main() {
        while (cin >> x >> y >> c) {
            double l = 0, r = min(x, y), mid;
            int cnt = 99;
            while (cnt--) {
                mid = (l + r) / 2.0;
                if (judge(mid)) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            cout << fixed << setprecision(3) << mid << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    test20180922 倾斜的线
    test20180921 量子纠缠
    test20180921 手机信号
    test20180919 选择客栈
    BZOJ3083 遥远的国度
    test20180907 day1
    [ZJOI2010]基站选址
    HDU3584 Cube
    POJ2155 Matrix
    test20180902 day1
  • 原文地址:https://www.cnblogs.com/IzumiSagiri/p/15220799.html
Copyright © 2020-2023  润新知