Land Overseer(2021_0919_ICPC网络赛第一场F题)

The role of Keqing, Yuheng of the Liyue Qixing, is to manage real estate and construction in Liyue.Today Keqing decides to leave her office and visit two places - Chasm, and Jueyun Karst - to make sure the building progress is at a reasonable pace.The location of Keqing’s office and the two places to visit can be denoted as three points on a 2D Cartesian coordinate system.

Keqing’s office, the start point, is located at point O (0, 0).
Chasm is located at point A (a, b).
Jueyun Karst is located at point B (2a, 0).

Keqing plans to visit Chasm first and then go to Jueyun Karst. Because Keqing is an experienced land overseer, she does not need to be at the exact location to do her job. She can finish the visit if the distance between her and the target point is no greater than R.
Please help Keqing find the shortest path to visiting Chasm and Jueyun Karst.

Input

There are T test cases in this problem.
The first line has one integer T.
In the following T lines, each contains three integers a, b, R.
We guarantee that 0 < a, b, R < 109, a^2 + b^2 > 4R^2, and 0 < T ≤ 1000.

Output

For each test case, you should first print “Case #t: ” (without quotes), where t is the index of this test case.
Then in the same line, print a number L, the length of the shortest path to finish the visit, rounded to two decimal places.

Example

standard input

1
3 5 1

standard output

Case #1: 9.00

Note
In the sample input, we have Chasm at (3,5), Jueyun Karst at (6,0), and Keqing can finish the visiting within radius 1.
So Keqing could go directly to point (3,4) first to visit Chasm, then reach (5.4,0.8) to visit Jueyun Chasm.
The total length is 5+4=9. We can prove that there is no path with a smaller distance.

题意

输入三个数a b r

三个点分别是X(0,0),Y(a,b), Z(2a,0)

求X到 距离Y不大于r的点的距离再到距离Z不大于r的点的距离的最小值

思路

在这里插入图片描述
距离某点的距离不大于R就是以某点为圆心R为半径的圆的范围内的点

先找出第二个点所在的圆离原点最近的那个点,其实就是(a,b-r),判断b-r的正负,如果是正,最短距离就是原点到(a,b-r)的距离乘2-r,因为是等腰三角形;如果为负,说明圆一定包含了x轴的一部分,所以距离原点最近的那个点就认为是在x轴上,所以最短距离就是2*a-r

代码

#include<stdio.h>
#include<math.h>
int main()
{
    int t;
    scanf("%d",&t);
    int k=0;
    while(t--)
    {
        k++;
        double a,b,r;
        scanf("%lf %lf %lf",&a,&b,&r);
        double s3;
        if(b-r>0)
        {
            double s1=sqrt(a*a+(b-r)*(b-r));
            s3=2*s1-r;
        }
        else
            s3=2*a-r;
        printf("Case #%d: %.2f\n",k,s3);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值