LightOJ - 1062 Crossed Ladders(计算几何 + 二分)

链接 Crossed Ladders

题意

给出两个🏠,在一个房子底部放梯子搭到另一个🏠上,如图
在这里插入图片描述
给出梯子长度 x , y x, y x,y 和它们的交点高度 c c c , 求出两个🏠之间的街道宽度;

思路

首先很容易想到利用三角形相似;

三角形相似得出两个式子

w − a w = c x 2 − w 2 \frac{w -a}{w} = \frac{c}{\sqrt{x^2-w^2}} wwa=x2w2 c
a w = c y 2 − w 2 \frac{a}{w} = \frac{c}{\sqrt{y^2-w^2}} wa=y2w2 c

整理一下得

c y 2 − w 2 + c x 2 − w 2 − 1 = 0 \frac{c}{\sqrt{y^2-w^2}} + \frac{c}{\sqrt{x^2-w^2}} - 1=0 y2w2 c+x2w2 c1=0

分析可得这个关于 w w w 的方程是单调的,所以我们对 w w w 进行二分;

AC代码

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <string>

#define x first
#define y second

using namespace std;

const double eps = 1e-12;
const int N = 210;
typedef pair<double, double> PDD;
const double pi = acos(-1);

int T;
double x, y, c;

bool check(double u)
{
    return c / sqrt(y * y - u * u) + c / sqrt(x * x - u * u) - 1 >= 0;
}

int main()
{
    scanf("%d", &T);
    for (int i = 1; i <= T; i ++)
    {
        scanf("%lf%lf%lf", &x, &y, &c);

        double l = 0, r = min(x, y);

        while (r - l > eps)
        {
            double mid = (l + r) / 2.0;
            if (check(mid)) r = mid;
            else l = mid;
        }


        printf("Case %d: %.10lf\n", i, r);
    }
}

——END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半碗无糖蓝莓冻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值