Problem:


２都市間の距離

地球上の2 都市の北緯と東経を入力とし、地表距離を計算して出力するプログラムを作成してください。ただし、地球は半径 6,378.1 km の球とし、2 点間の地表距離とはこの球面に沿った最短距離です。また、南半球でも南緯は用いずに北緯 0 ~ -90 度を用い、グリニッジ子午線の西でも西経は用いずに東経 180 ~ 360 度を用いることとします。地表距離は km 単位で求め、小数点以下は四捨五入し、整数値として出力してください。

以下に主要都市の北緯、東経の例を示します。

地名 北緯(度) 東経(度)

東京     35.68 139.77

 シンガポール    1.37  103.92

  シドニー    -33.95 151.18

   シカゴ     41.78 272.25

ブエノスアイレス  -34.58 301.52

  ロンドン     51.15 359.82

Input

複数のデータセットの並びが入力として与えられます。入力の終わりは-1 四つの行で示されます。各データセットは以下の形式で与えられます。

a b c d

1 行に第 1 の都市の北緯 a、第 1 の都市の東経 b、第 2 の都市の北緯 c、第 2 の都市の東経 d が空白区切りで与えられます。入力はすべて実数で与えられます。

データセットの数は 30 を超えません。

Output

データセット毎に 2 都市の地表距離を１行に出力します。

Sample Input

35.68 139.77 51.15 359.82
1.37 103.92 41.78 272.25
51.15 359.82 -34.58 301.52
-1 -1 -1 -1

Output for the Sample Input

9609
15092
11112



Sample input:
35.68 139.77 51.15 359.82
1.37 103.92 41.78 272.25
51.15 359.82 -34.58 301.52
-1 -1 -1 -1


Sample output:
9609
15092
11112

Submission status: Wrong Answer

Solution code:
import math
R=6378.1
pi=math.pi
while 1:
	x1,y1,x2,y2=map(lambda x: float(x)*pi/180,raw_input().split())
	if x1<0:break
	cosin=math.cos(x1)*math.cos(x2)*math.cos(y1-y2) + math.sin(x1)*math.sin(x2)
	print int(R*math.acos(cosin)+1)

Submission status: Wrong Answer

Solution code:
import math
R=6378.1
pi=math.pi
while 1:
	x1,y1,x2,y2=map(lambda x: float(x)*pi/180,raw_input().split())
	if x1<0:break
	cosin=math.cos(x1)*math.cos(x2)*math.cos(y1-y2) + math.sin(x1)*math.sin(x2)
	print int(R*math.acos(cosin)+0.5)

Submission status: Wrong Answer

Solution code:
import math
R=6378.1
pi=math.pi
while 1:
	x1,y1,x2,y2=map(lambda x: float(x)*pi/180,raw_input().split())
	if x1<0:break
	cosin=math.cos(x1)*math.cos(x2)*math.cos(y1-y2) + math.sin(x1)*math.sin(x2)
	print int(round(R*math.acos(cosin)))

Submission status: Accepted

Solution code:
from math import *
r=pi/180
while 1:
    a,b,c,d=e=map(lambda x: float(x)*r,raw_input().split())
    if e==[-r]*4:break
    print int(round(6378.1*acos((sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b)))))

Submission status: Accepted

Solution code:
from math import *
r=pi/180
while 1:
 a,b,c,d=e=map(lambda x: float(x)*r,raw_input().split())
 if e==[-r]*4:break
 print int(round(6378.1*acos((sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b)))))

Submission status: Accepted

Solution code:
from math import sin,cos,acos,pi
while 1:
  A = map(float,raw_input().split())
  if all([e==-1 for e in A]):break
  [a,b,c,d] = [e*pi/180 for e in A]
  print int(round(acos(cos(a)*cos(c)*cos(b-d)+sin(a)*sin(c))*6378.1))

Submission status: Accepted

Solution code:
from math import *
while 1:
  A = map(float,raw_input().split())
  if A == [-1]*4: break
  a,b,c,d = map(radians, A)
  print int(round(acos(cos(a)*cos(c)*cos(b-d)+sin(a)*sin(c))*6378.1))

Submission status: Accepted

Solution code:
import math
def l2(x,y,z):
    return math.sqrt(x*x+y*y+z*z)
while True:
    s = input()
    if s == '-1 -1 -1 -1':
        break
    a,b,c,d = map(float, s.split())
    a = (a / 360) * 2 * math.pi
    b = (b / 360) * 2 * math.pi
    c = (c / 360) * 2 * math.pi
    d = (d / 360) * 2 * math.pi
    x1 = math.cos(b)*math.cos(a)
    y1 = math.sin(b)*math.cos(a)
    z1 = math.sin(a)
    x2 = math.cos(d)*math.cos(c)
    y2 = math.sin(d)*math.cos(c)
    z2 = math.sin(c)
    theta = math.acos(x1*x2 + y1*y2 + z1*z2)
    print(round(6378.1*theta))

Submission status: Accepted

Solution code:
from math import acos,sin,cos,radians
while 1:
    a,b,c,d=map(float,input().split())
    if a==b==c==d==-1:break
    a,c=radians(a),radians(c)
    print(int(6378.1*acos(sin(a)*sin(c) + cos(a)*cos(c)*cos(radians(d)-radians(b)))+0.5))

Submission status: Accepted

Solution code:
# Aizu Problem 0177: Distance Between Two Cities
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


R = 6378.1
while True:
    inp = input().split()
    if inp == ['-1'] * 4:
        break
    lat1, long1, lat2, long2 = [float(_) * math.pi / 180. for _ in inp]
    dist = round(R * math.acos(math.sin(lat1)*math.sin(lat2) + \
                               math.cos(lat1)*math.cos(lat2)*math.cos(long2-long1)), 0)
    print(int(dist))

Submission status: Accepted

Solution code:
# AOJ 0177 Distance Between Two Cities
# Python3 2018.6.19 bal4u

PI = 3.1415926535897932384626433832795
M = (PI/180.0)

import math

while True:
	y1, x1, y2, x2 = list(map(float, input().split()))
	if x1 == -1 and y1 == -1 and x2 == -1 and y2 == -1: break
	a = math.cos(y1*M)*math.cos(y2*M)*math.cos((x1-x2)*M) + math.sin(y1*M)*math.sin(y2*M)
	print(int(6378.1*math.acos(a) + 0.5))

Submission status: Accepted

Solution code:
from math import *

while True:
    a,b,c,d=map(float,raw_input().split())
    if a==b==c==d==-1:break
    rd=pi/180
    a,b,c,d=a*rd,b*rd,c*rd,d*rd
    print int(round(6378.1*acos((sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b)))))

Submission status: Accepted

Solution code:
from math import * 
R=6378.1
while 1:
	a,b,c,d=map(float,raw_input().split())
	if (a,b,c,d)==(-1,-1,-1,-1):break
	rd=pi/180
	a,b,c,d=a*rd,b*rd,c*rd,d*rd
	cosin=cos(a)*cos(c)*cos(b-d)+sin(a)*sin(c)
	print int(round(R*acos(cosin)))

Submission status: Accepted

Solution code:
import math
r =  6378.1
def getRadian(degree):
    return degree * math.pi / 180

while(1):
    a,b,c,d = (float(x) for x in input().split())
    if a == -1 and b == -1 and c == -1 and d == -1:
        break
    cos = math.cos(getRadian(a)) * math.cos(getRadian(c)) * math.cos(getRadian(b) - getRadian(d)) + math.sin(getRadian(a)) * math.sin(getRadian(c))
    dist = r * math.acos(cos)
    print(format(dist, '.0f'))

Submission status: Accepted

Solution code:
from math import pi, acos, cos, sin

while 1:
    *S, = map(float, input().split())
    if all(e == -1 for e in S):
        break
    a, b, c, d = map(lambda x: pi * x / 180., S)
    x = 6378.1 * acos(sin(a)*sin(c) + cos(a)*cos(c)*cos(b-d))
    print(round(x))

Submission status: Accepted

Solution code:
import math

while 1:
    a, b, c, d = map(float, input().split())
    if a == -1:
        break

    a = (a / 360) * 2 * math.pi
    b = (b / 360) * 2 * math.pi
    c = (c / 360) * 2 * math.pi
    d = (d / 360) * 2 * math.pi

    x1 = math.cos(b) * math.cos(a)
    y1 = math.sin(b) * math.cos(a)
    z1 = math.sin(a)
    x2 = math.cos(d) * math.cos(c)
    y2 = math.sin(d) * math.cos(c)
    z2 = math.sin(c)

    angle = math.acos(x1*x2 + y1*y2 + z1*z2)
    print(round(6378.1 * angle))