南邮 OJ 1516 E_TRC1

本文探讨了从一个地点到另一个地点的最短路径计算方法,对比了沿地球表面的大圆路径与通过地心的直线路径的距离差异。通过使用球面几何原理,计算了两点间的实际距离与理想距离,并提供了具体的数学公式与示例计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

E_TRC1

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 18            测试通过 : 16 

比赛描述

There are different methods of transporting people fromplace to place: cars, bikes, boats, trains, planes, etc.For very long distances, people generally fly in a plane.But this has the disadvantage that the plane must flyaround the curved surface of the earth. A distancetravelled would be shorter if the traveller followed astraight line from one point to the other through atunnel through the earth.For example, travelling from Waterloo to Cairo requires adistance of 9293521 metres following the great circle route around the earth, butonly 8491188 metres following the straight line through the earth.For this problem, assume that the earth is a perfect sphere with radius of6371009 metres.



输入

The first line of input contains a single integer, the number of test cases tofollow. Each test case is one line containing four floating point numbers: thelatitude and longitude of the origin of the trip, followed by the latitude andlongitude of the destination of the trip. All of these measurements are indegrees. Positive numbers indicate North latitude and East longitude, whilenegative numbers indicate South latitude and West longitude.

输出

For each test case, output a line containing a single integer, the difference inthe distance between the two points following the great circle route around thesurface of the earth and following the straight line through the earth, inmetres. Round the difference of the distances to the nearest integer number ofmetres.

样例输入

1
43.466667 -80.516667 30.058056 31.228889

样例输出

802333

提示

undefined

题目来源

Waterloo local contest




/*
#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define eps 1e-8
struct Point
{
	Point (double xx=0,double yy=0) : x(xx) , y(yy) { }
	double x;
	double y;
};

typedef Point Vector;
Vector operator+(Vector  v1,Vector  v2) { return Vector(v1.x+v2.x,v1.y+v2.y); }
Vector operator-(Vector  v1,Vector  v2) { return Vector(v1.x-v2.x,v1.y-v2.y); }
Vector operator*(Vector  v, double p) { return Vector(v.x*p,v.y*p); }
Vector operator/(Vector  v,double p) { return Vector(v.x/p,v.y/p); }

bool operator < (Point  a,Point  b) { return a.x < b.x || (a.x==b.x && a.y < b.y); }
int dcmp(double x) 
{
	if (fabs(x) < eps) return 0;
	return x < 0 ? -1 : 1; 
}
bool operator==(const Point & a,const Point & b) 
{
	return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}

double Dot(Vector  A,Vector  B) { return A.x*B.x+A.y*B.y; }
double Length(Vector  A) { return sqrt(Dot(A,A)); }
double Angle(Vector A,Vector B) { return acos(Dot(A,B)/Length(A)/Length(B)); }
double Cross(Vector A,Vector B) { return A.x*B.y-A.y*B.x; }
double Area2(Point a,Point b,Point c) {  return Cross(b-a,c-a); }
Vector Rotate(Vector A,double rad) 
{
	return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
Vector Normal(Vector A) { double L = Length(A); return Vector(-A.y/L,A.x/L); }

//点和直线
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
	Vector u = P-Q;
	double t = Cross(w,u) / Cross(v,w);
	return P+v*t;
}
double DistanceToLine(Point P,Point A,Point B) 
{
	Vector v1 = B-A , v2 = P-A;
	return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(Point P,Point A,Point B)
{
	if (A==B) return Length(P-A);
	Vector v1 = B-A , v2 = P-A , v3 = P-B;
	if (dcmp(Dot(v1,v2)) < 0) return Length(v2);
	else if (dcmp(Dot(v1,v3)) > 0) return Length(v3);
	else return fabs(Cross(v1,v2))/Length(v1);
}
Point GetLineProjection(Point P,Point A,Point B) 
{
	Vector v = B-A;
	return A+v*(Dot(v,P-A)/Dot(v,v));
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2) 
{
	double c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1) ,
		     c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
	return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4)<0;
}
bool OnSegment(Point p,Point a,Point b) {
	return dcmp(Cross(a-p,b-p))==0 && dcmp(Dot(a-p,b-p)) < 0;
}
*/
//--------------------------------------------------------------------------------------------


#include<iostream>
#include<cmath>
const double PI = 4*atan(1.0);
const double R = 6371009;

double xx1,yy1,zz1,xx2,yy2,zz2;
double weidu , jingdu;
double sqr(double x) { return x*x; }

int main(){
	int T; 
	scanf("%d",&T);
	while (T--) {
		scanf("%lf%lf",&weidu,&jingdu);
		weidu = weidu*PI/180;
		jingdu = jingdu*PI/180;
		xx1 = R*cos(weidu)*cos(jingdu);
		yy1 = R*cos(weidu)*sin(jingdu);
		zz1 = R*sin(weidu);
		scanf("%lf%lf",&weidu,&jingdu);
		weidu = weidu*PI/180;
		jingdu = jingdu*PI/180;
		xx2 = R*cos(weidu)*cos(jingdu);
		yy2 = R*cos(weidu)*sin(jingdu);
		zz2 = R*sin(weidu);
		double dist = sqrt(sqr(xx1-xx2)+sqr(yy1-yy2)+sqr(zz1-zz2));
		double ang = acos((xx1*xx2+yy1*yy2+zz1*zz2)/(R*R));
		double dist2 = ang*R;
		printf("%.0lf\n",dist2-dist);
	}
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值