-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathPython.py
51 lines (40 loc) · 1.29 KB
/
Python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#****************************************#
#* *#
#* CodinGame.com Solutions by pathosDev *#
#* *#
#* Puzzle: Defibrillators *#
#* Difficulty: Easy *#
#* Date solved: 08.11.2018 *#
#* *#
#****************************************#
import sys
import math
#Calculates the distance between two points on earth.
def distance(lonA, latA, lonB, latB):
lonA = math.radians(lonA)
lonB = math.radians(lonB)
latA = math.radians(latA)
latB = math.radians(latB)
x = (lonB - lonA) * math.cos((latA + latB) / 2)
y = latB - latA
return math.sqrt(x * x + y * y) * 6371
#Read inputs.
lonA = float(input().replace(',', '.'))
latA = float(input().replace(',', '.'))
N = int(input())
#Define minimum.
min = sys.maxsize
minName = ''
for i in range(N):
#Read defibrillator.
DEFIB = input().split(';')
lonB = float(DEFIB[4].replace(',', '.'))
latB = float(DEFIB[5].replace(',', '.'))
#Calculating distance for current defibrillator.
d = distance(lonA, latA, lonB, latB)
#Set nearest defibrillator.
if d < min:
min = d
minName = DEFIB[1]
#Print nearest defibrillator.
print(minName);