Ultraviolet A 11817 (spherical)
This topic mainly describes how to convert longitude and latitude to three-dimensional coordinate points.
Code:
# Include
# Include
# Include
# Include using namespace std; const double PI = acos (-1.0); int t; double lat [2], lng [2]; // convert angle to radian double torad (double deg) {return deg/180 * PI;} struct Point3 {double x, y, z; Point3 () {} Point3 (double x, double y, double z) {this-> x = x; this-> y = y; this-> z = z ;}}; const double R = 6371009; Point3 get_coord (double R, double lat, double lng) {lat = torad (lat); lng = torad (lng ); return Point3 (R * cos (lat) * cos (lng), R * cos (lat) * sin (lng), R * sin (lat ));} double dist (Point3 p, Point3 q) {double dx = p. x-q. x; double dy = p. y-q. y; double dz = p. z-q. z; return sqrt (dx * dx + dy * dy + dz * dz);} int main () {scanf ("% d", & t); while (t --) {scanf ("% lf", & lat [0], & lng [0], & lat [1], & lng [1]); point3 p [2]; p [0] = get_coord (R, lat [0], lng [0]); p [1] = get_coord (R, lat [1], lng [1]); double d = dist (p [0], p [1]); printf ("%. 0f \ n ", 2 * asin (d/2/R) * R-d);} return 0 ;}