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 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.
Input
There 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 fro M 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.
Output
If It is impossible-find out the distance from C to D with these data, you should print "impossible.", otherwise AR E to print "Distance are x miles.", where X is the required Distance in kilometers (rounded to the integer number).
Sample
Input
4 7 5 7
Output
Distance is 5385 miles.
Test instructions: There are ABCD four points on the circle, arranged in order (i.e. B must be between AC). Then according to the input four edges.
Procedure: Because the circumference angle of the chord is equal, so ∠a==∠b. The cosine theorem is then used in the triangular ADC and the triangular BCD. Two equations can be obtained. Unknown only Cos∠a and DC, a two-tuple equation, a simple simplification will be able to find the DC.
Cosine theorem A^2=b^2+c^2-2*b*c*cos (∠a);
#pragma warning (disable:4786) #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <malloc.h> #include <ctype.h> #include <math.h> #include <string># Include <iostream> #include <algorithm>using namespace std; #include <stack> #include <queue># Include <vector> #include <deque> #include <set> #include <map> #define INF 999999999#define EPS 0.00001#define LL __int64d#define Pi ACOs ( -1.0) int main () {double zuo,you,c,ans,ad,ac,bd,bc;while (scanf ("%lf%lf%LF%LF ", &AD,&AC,&BD,&BC)!=eof) {if (ad*ac==0| | bd*bc==0) {puts ("impossible."); Continue;} zuo= (AD*AD+AC*AC)/(2.0*AD*AC); you= (BD*BD+BC*BC)/(2.0*BD*BC); C= (2*BD*BC-2*AD*AC)/(2*BD*BC*2*AD*AC); if (c==0| | (zuo-you)/c<0) {puts ("impossible."); Continue;} Ans=sqrt ((zuo-you)/C);p rintf ("Distance is%.0LF km.\n", ans*1000); } return 0; }
URAL 1294. Mars Satellites Geometry