URAL 1294. Mars Satellites 几何

1294. Mars SatellitesTime limit: 1.0 secondMemory limit: 64 MBFour 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.InputThere 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.OutputIf 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).Sampleinput

4 7 5 7

output

Distance is 5385 km.

题意:有ABCD四个点在圆上,,按顺序排列(也就是说B一定在AC之间)。 然后根据输入的四条边。

做法:因为同弦的圆周角相等,所以∠A==∠B。 然后在三角形ADC和三角形BCD中各用一遍余弦定理。可以得到两个方程。未知的只有cos∠A 和 DC,一个二元方程组,化简一下就可以求出DC了。

余弦定理 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);printf("Distance is %.0lf km.\n",ans*1000); } return 0; }

只能昏昏沉沉地沿着青草和泥土的气息前进。

URAL 1294. Mars Satellites 几何

相关文章:

你感兴趣的文章:

标签云: