URAL 1294. Mars Satellites (cosine theorem math ah)

Source: Internet
Author: User

Title Link: http://acm.timus.ru/problem.aspx?space=1&num=1294


1294. Mars Satellitestime limit:1.0 Second
Memory limit:64 MB
Four artificial satellites travel in one plane along the areostationary orbit around Mars. They has code names A, B, C and D and travel exactly in the this order. Venus ' s Scouts for military purposes (for-what particular purpose they do not say) decided to find a distance between sat Ellites C and D. All Mars satellites could measure distances to the other satellites, that's why all-what's needed to do are to penetrate In the computer system of satellite C and measure, the distance to satellite D (or vice versa). Nevertheless, Martians is not so stupid and has not very bad defense. That's why all could Venus's scouts do are 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 does not know how to find the distance F Rom C to D using these measurements. You can help them. Inputthere is 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. Assume the radius of the orbit equal to 20392 miles as it should is for the real areostationary orbit. Outputif It is impossible-find out the distance from C to D with these data, you should print "impossible.", otherwise You ' to ' print ' Distance is x miles. ', where X is the required Distance in kilometers (rounded to the integer number). Sample
input Output
4 7 5 7
Distance is 5385 miles.


Test instructions

In a circle there is a fixed order of four points, tell you the distance of the ad AC BD BC, the distance to the CD!

Ps:

Equal to the central angle of equal chord in the same circle

The code is as follows:

#include <cstdio> #include <cmath>//equal to the central angle of equal chord in the same circle int main () {    int ad, AC, BD, BC;    while (~SCANF ("%d%d%d%d", &AD,&AC,&BD,&BC))    {        if (Ad*ac = = BD*BC)//denominator equal, subtract to zero        {            printf ("impossible.\n");            Continue;        }        Cosine theorem Simplification:        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 (cosine theorem math ah)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.