码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-03-08 10:32:13      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:ural   数学   余弦定理   

题目链接: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

input output
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;
}


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

标签:ural   数学   余弦定理   

原文地址:http://blog.csdn.net/u012860063/article/details/44131149

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!