南邮 OJ 1516 E_TRC1

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);
	}
}







你可能感兴趣的:(ACM,南邮OJ,E_TRC1)