## UVA11817 – Tunnelling the Earth

2019年11月08日 ⁄ 综合 ⁄ 共 2080字 ⁄ 字号 评论关闭

```#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const double pi=acos(-1),r=6371009;
double cg(double a)
{
return a/180*pi;
}
int main()
{
int t;
double a,b,c,d,x,y,z;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
a=cg(a);b=cg(b);c=cg(c);d=cg(d);
z=r*sin(a);z=r*sin(c);
y=r*cos(a)*sin(b);y=r*cos(c)*sin(d);
x=r*cos(a)*cos(b);x=r*cos(c)*cos(d);
a=pow(x-x,2)+pow(y-y,2)+pow(z-z,2);
b=acos(1-a/2/r/r);
b=r*b;
a=sqrt(a);
printf("%.0lf\n",b-a);
}
}```

Time limit: 1.000 seconds

## Problem E: Tunnelling the Earth 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 fly aroundthe curved surface of the earth. A distance travelled wouldbe shorter if the traveller followed a straight line fromone point to the other through a tunnel through the earth.

For example, travelling from Waterloo to Cairo requires adistance of 9293521 metres following the great circle route aroundthe earth, but only 8491188 metres following the straight linethrough the earth.

For this problem, assume that the earth is a perfect sphere withradius of 6371009 metres.

#### Input Specification

The first line of input contains a single integer, the number of testcases to follow. Each test case is one linecontaining four floating point numbers:the latitude and longitude of the origin of the trip,followed by the latitude and longitude of the destination
ofthe trip. All of these measurements are in degrees.Positive numbers indicate North latitude and East longitude,while negative numbers indicate South latitude and West longitude.

#### Sample Input

```1
43.466667 -80.516667 30.058056 31.228889
```

#### Output Specification

For each test case, output a line containing a single integer, thedifference in the distance between the two points following the greatcircle route around the surface of the earth and following the straightline through the earth, in metres. Round the difference
of thedistances to the nearest integer number of metres.

#### Output for Sample Input

```802333
```

Ondřej Lhoták
【上篇】
【下篇】