UVA 10221 题解
大意
给出圆的半径
思路
假设
以度为单位:
-
圆弧距离:
arc=2 \pi r \times \dfrac{angle}{360 \times 60} -
直线弦距离:
dis=r \times \operatorname{sin}(\dfrac{angle \times \pi}{2 \times 180 \times 60}) \times 2
以分为单位:
-
圆弧距离:
arc=2 \pi r \times \dfrac{angle}{360} -
直线弦距离:
dis=r \times \operatorname{sin}(\dfrac{angle \times \pi}{2 \times 180 \times 60}) \times 2
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double r = 6440; //地球半径
int main() {
double s, a;//s:卫星与地球表面的距离,a:两颗卫星对地球中心的夹角
string str;
while (cin >> s >> a >> str) {
if (str[0] == 'm') {
a /= 60;//分转换为度
}
double angle = M_PI * a / 180;
double arc = angle * (s + r);//圆弧距离
double dis = 2 * (s + r) * sin(angle / 2);//直线弦距离
if (a > 180) {//夹角大于180度
arc = 2 * M_PI * (s + r) - arc;
}
cout << fixed << setprecision(6) << arc;
cout << " ";
cout << fixed << setprecision(6) << dis;
cout << "\n";
}
return 0;
}