E题题解

E题题解

发表于 2021-01-20

E - Satellites

题目描述

The radius of earth is 6440 Kilometer. There are many Satellites and Asteroids moving around the earth. If two Satellites create an angle with the center of earth, can you find out the distance between them? By distance we mean both the arc and chord distances. Both satellites are on the same orbit (However, please consider that they are revolving on a circular path rather than an elliptical path).

Input The input file will contain one or more test cases. Each test case consists of one line containing two-integer s and a, and a string ‘min’ or ‘deg’. Here s is the distance of the satellite from the surface of the earth and a is the angle that the satellites make with the center of earth. It may be in minutes (′ ) or in degrees (◦ ). Remember that the same line will never contain minute and degree at a time.

Output For each test case, print one line containing the required distances i.e. both arc distance and chord distance respectively between two satellites in Kilometer. The distance will be a floating-point value with six digits after decimal point.

Sample Input

500 30 deg

700 60 min

200 45 deg

Sample Output

3633.775503 3592.408346

124.616509 124.614927

5215.043805 5082.035982

解析

角度单位是分(′ )和度(◦ ),1°=60′。设圆心角angle[0,180°]。则圆弧距离distance1=(2 * PI * r * angle)/360;直线距离distance2=r * sin((angle*PI)/2 * 180) * 2;

如果以分为单位,将上式的angle替换成angle/60即可;

实现代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double r=6440;
int main()
{
double a1,a2;
char s[10];
while(cin>>a1>>a2>>s)
{
if(s[0]=='m')//判断输入度数的单位
a2=a2/60;//分转度
double angle=M_PI*a2/180;//转换为弧度制
double arc=angle*(a1+r);//计算弧长
double dis=2*(a1+r)*sin(angle/2);//计算两点直线距离
if(a2>180)
arc=2*M_PI*(a1+r)-arc;//角度大于180的情况
cout<<setprecision(6)<<setiosflags(ios::fixed)<<arc<<" "<<dis<<endl;
}
return 0;
}