跳到正文

题解

题解:UVA10221 Satellites

lee_liang约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年10月11日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 2 分钟
题目
UVA10221

版本

  1. v1当前

题意很明确,不多说。

分析

设:

  • 地球半径 R=6440R = 6440 km
  • 卫星高度 ss km
  • 卫星轨道半径 r=R+sr = R + s km
  • 圆心角 θ\theta(弧度)

两颗卫星的位置关系如下图所示:

代码
   卫星甲
    / \
   /   \
  /θ    \
地球-----卫星乙

距离计算公式

弧线距离:

arc=r×θ \text{arc} = r \times \theta

弦线距离:

chord=2×r×sin⁡(θ2) \text{chord} = 2 \times r \times \sin\left(\frac{\theta}{2}\right)

单位转换

输入的角度单位可能是度或分,需要统一转换为弧度:

  • 如果单位是度:θ=a×π180\theta = a \times \frac{\pi}{180}
  • 如果单位是分:θ=a60×π180\theta = \frac{a}{60} \times \frac{\pi}{180}

注:如果输入角度大于 180∘180^\circ,应该取其补角。

具体实现

读入完之后计算轨道半径 r=6440+sr = 6440 + s,根据单位将角度转换为弧度 θ\theta。

确保 θ≤π\theta \leq \pi(如果大于 π\pi,取 2π−θ2\pi - \theta)

然后套公式输出即可。

代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const double r=6440.0;
const double pi=acos(-1.0);
signed main(){
	double s,a;string u;
	while(cin>>s>>a>>u){
		double r_now=r+s;
		double ar;
		if(u=="deg")ar=a*pi/180.0;
		else ar=(a/60.0)*pi/180.0;
		if(ar>pi)ar=2*pi-ar;
		double ans=r_now*ar;
		double anns=2*r_now*sin(ar/2);
		cout<<fixed<<setprecision(6)<<ans<<' '<<anns<<'\n';
	}
	return 0;
}
原文