Skip to content

Instantly share code, notes, and snippets.

@LiamHz
Last active August 29, 2018 17:13
Show Gist options
  • Save LiamHz/e732c2b6f4e7d57af69cad01df1602b9 to your computer and use it in GitHub Desktop.
Save LiamHz/e732c2b6f4e7d57af69cad01df1602b9 to your computer and use it in GitHub Desktop.
Solution to S1 of the 2018 CCC
#Number of villages
N = int(input())
#List of village positions
villages = list()
for i in range(N):
villages.append(float(input()))
#List of distances between villages
distances = list()
#Sort the villages, from small to large, based on their positions
villages.sort()
#First and last villages distances are infinite
for i in range(1, N - 1):
#Calculate neighborhood size for each village other than the first and last
distances.append( (villages[i+1] - villages[i]) / 2 + (villages[i] - villages[i - 1]) / 2 )
#Sort distances from small to large
distances.sort()
#Print Smallest
print(distances[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment