URAL 1294. Mars Satellites(余弦定理 数学)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1294


1294. Mars Satellites

Time limit: 1.0 second
Memory limit: 64 MB
Four artificial satellites travel in one plane along the areostationary orbit around Mars. They have code names A, B, C and D and travel exactly in this order. Venus’s scouts for military purposes (for what particular purpose they did not say) decided to find a distance between satellites C and D. All Mars satellites could measure distances to the other satellites, that is why all what is needed to do is to penetrate in the computer system of satellite C and measure the distance to satellite D (or vice versa). Nevertheless, Martians are not so stupid and have not very bad defense. That is why all what could Venus’s scouts do is to break the defense of satellites A and B (that were older models). They measured distances from satellites A and B to satellites C and D, but now they do not know how to find the distance from C to D using these measurements. You can help them.

Input

There are 4 numbers: distances from A to D, from A to C, from B to D and from B to C in thousands kilometers (integers from 1 to 10000). Satellites can measure distance even through the planet and you may assume that orbit is a circle. Do not assume the radius of the orbit equal to 20392 km as it should be for the real areostationary orbit.

Output

If it is impossible to find out the distance from C to D with these data, you should print "Impossible.", otherwise you are to print "Distance is X km.", where X is the required distance in kilometers (rounded to the integer number).

Sample

inputoutput
4 7 5 7
Distance is 5385 km.


题意:

在一个圆上有有固定顺序的四点,告诉你AD AC BD BC的距离,求 CD的距离!

PS:

//同圆中相等弦所对的圆心角相等

代码如下:

#include <cstdio>
#include <cmath>
//同圆中相等弦所对的圆心角相等
int main()
{
    int ad, ac, bd, bc;
    while(~scanf("%d%d%d%d",&ad,&ac,&bd,&bc))
    {
        if(ad*ac == bd*bc)//分母相等,相减为零
        {
            printf("Impossible.\n");
            continue;
        }
        //余弦定理化简得:
        double t1 = (ad*ad+ac*ac)*2.0*bd*bc-(bd*bd+bc*bc)*2.0*ad*ac;
        double t2 = 2*bd*bc-2*ad*ac;
        double tt = t1*1.0/t2;
        if(tt < 0)
        {
            printf("Impossible.\n");
        }
        else
        {
            tt = sqrt(tt);
            printf("Distance is %.0lf km.\n",tt*1000);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值