URAL 1294. Mars Satellites 几何

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

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;
}
时间: 2024-10-27 07:44:44

URAL 1294. Mars Satellites 几何的相关文章

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

URAL - 1793 Tray 2(几何题)

Tray 2 Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description One of the organizers of the Ural Regional School Programming Contest came to the university cafeteria to have lunch. He took a soup and a ma

URAL 1287. Mars Canals 滚动数组+DP

求从上到下 从左到右 从左上到右下 从右上到左下的 最长的S和s串 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1444; char a[maxn][maxn]; int dp[2][maxn][2][4]; int main() { int n; int ans1 = 0, ans2 = 0; scanf("%d

poj 1266 Cover an Arc.

http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 823   Accepted: 308 Description A huge dancing-hall was constructed for the Ural State University's 80-th anniversary celebration. The size of t

URAL - 1963(几何)

不知道是不是几何题,反正就是找对称,值得注意的是,对称轴不一定过点,还可能在边上 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const double mm=1e-7; double x[10],y[10]; bool deng(double a,double

ural 1020. Rope(几何)

题目链接:ural 1020. Rope 题目大意:按照顺序给定N个点,每个点有半径R,问说用线环绕N个点所需要的长度. 解题思路:因为需要围成一个圈,所以旋转角度一定是一周,板径又都相同,所以直接就是两两点之间的距离加上一个周长. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int maxn = 1

【BZOJ】1382: [Baltic2001]Mars Maps (线段树+扫描线)

1382: [Baltic2001]Mars Maps Time Limit: 5 Sec  Memory Limit: 64 MB Description 给出N个矩形,N<=10000.其坐标不超过10^9.求其面积并 Input 先给出一个数字N,代表有N个矩形. 接下来N行,每行四个数,代表矩形的坐标. Output 输出面积并 Sample Input 2 10 10 20 20 15 15 25 30 Sample Output 225 本以为是傻逼题,没想到不容易啊- 线段树+扫描

hdu1800 Flying to the Mars(字典树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14340    Accepted Submission(s): 4572 Problem Description In the year 8888

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in