Codeforces Gym-101116-F (Flight Plan)【三角函数】

本文介绍了一种计算地球表面上两点间距离的方法,通过转换经纬度坐标到直角坐标,利用球面三角公式计算两点间的球面距离及沿纬线和经线的路径长度。

原文地址

题目大意:
假设地球是一个球体,给出起点的经纬度A(x1,y1),A(x1,y1), 终点的经纬度B(x2,y2)B(x2,y2)。 
x:x: 纬度,北纬为正,南纬为负; 
y:y: 经度,东经为正,西经为负。 
令: 
D1D1为两点的距离; 
D2D2为起点AA先沿着纬线,再沿着经线 走到终点BB的距离。 
求D1,D2求D1,D2。

数据范围:
1≤T≤100001≤T≤10000 
|x1|,|x2|≤90,|y1|,|y2|≤180|x1|,|x2|≤90,|y1|,|y2|≤180
解题思路:
这道题不重要,重要的是怎么求地球上两点的距离。 

图的话,将就看这个吧!懒得画了,,,只看图就好,,, 
 

球面坐标和直角坐标存在一一对应的关系:球面有一点M(r,φ,θ)M(r,φ,θ), 
 
则,点MM的直角坐标和球面坐标的关系为: 
⎧⎩⎨x=rcosφcosθy=rcosφsinθz=rsinφ
{x=rcos⁡φcos⁡θy=rcos⁡φsin⁡θz=rsin⁡φ

设A(r,α,β),B(r,φ,θ)设A(r,α,β),B(r,φ,θ), 
则有OA→=(rcosαcosβ,rcosαsinβ,rsinα),OB→=(rcosφcosθ,rcosφsinθ,rsinφ)则有OA→=(rcos⁡αcos⁡β,rcos⁡αsin⁡β,rsin⁡α),OB→=(rcos⁡φcos⁡θ,rcos⁡φsin⁡θ,rsin⁡φ) 
由此可得,夹角ang=arccos(OA→⋅OB→|OA→|⋅|OB→|)ang=arccos⁡(OA→⋅OB→|OA→|⋅|OB→|) 

化简得:ang=arccos(cosαcosφcos(β−θ)+sinαsinφ)ang=arccos⁡(cos⁡αcos⁡φcos⁡(β−θ)+sin⁡αsin⁡φ) 
夹角出来了,距离就好办了。 
 

 

 

距离的问题解决了,其他都不重要了。不对,这道题还没完呢!,,, 
有一个坑点:当一个点在东半球,另一个在西半球时,需要特别注意一下角度,稍微想想。 

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const double R=6371.0;
int main()
{
	int t;
	double dd;
	double wa,wb,ja,jb;

	cin>>t;
	while(t--)
	{
		scanf("%lf%lf%lf%lf",&wa,&ja,&wb,&jb);

		if(abs(ja-jb)>180.0)
		{
			if(ja<0.0)
				ja+=360.0;
			else if(jb<0.0)
				jb+=360.0;
		}


		dd=R*acos(sin(wa/180.0*PI)*sin(wb/180.0*PI)+cos(wa/180.0*PI)*cos(wb/180.0*PI)*cos((ja-jb)/180.0*PI));
		printf("%.10lf ",dd);
		double wc=wa;
		double jc=jb;
		double d1=R*acos(sin(wb/180.0*PI)*sin(wc/180.0*PI)+cos(wb/180.0*PI)*cos(wc/180.0*PI)*cos((jb-jc)/180.0*PI));
		double r=R*cos(wa/180.0*PI);
		double d2=(abs(ja-jc)/180.0*PI)*r;
		printf("%.10lf\n",d1+d2);
	}
	return 0;
}

 

### Codeforces Problem 976C Solution in Python For solving problem 976C on Codeforces using Python, efficiency becomes a critical factor due to strict time limits aimed at distinguishing between efficient and less efficient solutions[^1]. Given these constraints, it is advisable to focus on optimizing algorithms and choosing appropriate data structures. The provided code snippet offers insight into handling string manipulation problems efficiently by customizing comparison logic for sorting elements based on specific criteria[^2]. However, for addressing problem 976C specifically, which involves determining the winner ('A' or 'B') based on frequency counts within given inputs, one can adapt similar principles of optimization but tailored towards counting occurrences directly as shown below: ```python from collections import Counter def determine_winner(): for _ in range(int(input())): count_map = Counter(input().strip()) result = "A" if count_map['A'] > count_map['B'] else "B" print(result) determine_winner() ``` This approach leverages `Counter` from Python’s built-in `collections` module to quickly tally up instances of 'A' versus 'B'. By iterating over multiple test cases through a loop defined by user input, this method ensures that comparisons are made accurately while maintaining performance standards required under tight computational resources[^3]. To further enhance execution speed when working with Python, consider submitting codes via platforms like PyPy instead of traditional interpreters whenever possible since they offer better runtime efficiencies especially important during competitive programming contests where milliseconds matter significantly.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值