# coreBugZJ

## How Long Is it， FZU 2011年3月月赛之 G， FZU 2016

Problem 2016 How Long Is it

## Problem Description

You are given two points in earth. (Points are described as the latitude (between -90 and +90 degrees) and longitude (between -180 and +180 degrees)) You are expected to calculate the distance between them ( in km). In this problem the radius of earth is 6378 km.

## Input

In the first line one integer T indicates the number of test cases. (T <= 1000)

For each case, only two points each giving the latitude (between -90 and +90 degrees) and longitude (between -180 and +180 degrees) .

## Output

For each test case, output the distance between them, the answer should accurate to 0.01.

4
-90 180 -90 90
-90 180 -90 90
-90 0 -90 90
-90 0 90 90

0.00
0.00
0.00
20037.08

## Source

FOJ有奖月赛-2011年03月

1 #include <iostream>
2 #include <cstdio>
3 #include <cmath>
4
5 using namespace std;
6
7 const double PI = 3.141592653589793;
8 const double R = 6378;
9
10 #define  A(x)  ( (x) * PI / 180.0 )
11
12 int main() {
13         int td, a, b, c, d;
14         double da, db, dc, dd, px, py, pz, qx, qy, qz, ang, dist;
15         scanf( "%d"&td );
16         while ( td-- > 0 ) {
17                 scanf( "%d%d%d%d"&a, &b, &c, &d );
18                 da = A(a);
19                 db = A(b);
20                 dc = A(c);
21                 dd = A(d);
22
23                 pz = R * sin( da );
24                 qz = R * sin( dc );
25
26                 px = R * cos( da ) * cos( db );
27                 qx = R * cos( dc ) * cos( dd );
28
29                 py = R * cos( da ) * sin( db );
30                 qy = R * cos( dc ) * sin( dd );
31
32                 ang = acos( (px*qx+py*qy+pz*qz) /
33                                 sqrt(px*px+py*py+pz*pz) /
34                                 sqrt(qx*qx+qy*qy+qz*qz)    );
35                 dist = R * ang;
36
37                 printf( "%0.2lf\n", dist );
38         }
39         return 0;
40 }
41

posted on 2011-03-20 20:49 coreBugZJ 阅读(1265) 评论(0)  编辑 收藏 引用 所属分类: ACM 