# Closest Two Points

Jul 10th, 2019
189
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import math
2. import sys
3. from functools import reduce
4.
5.
6. class Point:
7. def __init__(self, x, y):
8. self.x = x
9. self.y = y
10.
11. @classmethod
12. def calculate(cls, p1, p2):
13. cls.distance = math.sqrt(abs(p1.x - p2.x) ** 2 + abs(p1.y - p2.y) ** 2)
14. return float(cls.distance)
15.
16.
17. number_of_points = int(input())
18. all_points = []
19. min_distance = sys.maxsize
20.
21. for points in range(number_of_points):
22. points_coordinates = list(map(int, input().split(" ")))
23. # p = Point(points_coordinates[0], points_coordinates[1])
24. all_points.append(points_coordinates)
25.
26. for i in range(len(all_points)):
27. for p in range(len(all_points)):
28. if i == p:
29. continue
30. point1 = Point(all_points[i][0], all_points[i][1])
31. point2 = Point(all_points[p][0], all_points[p][1])
32.
33. result = Point.calculate(point1, point2)
34. if result < min_distance:
35. min_distance = result
36. firs_point = list(map(str, [item for item in all_points[i]]))
37. second_point = list(map(str, [item for item in all_points[p]]))
38.
39. print(f"{min_distance:.3f}")
40. print(f"({', '.join(firs_point)})")
41. print(f"({', '.join(second_point)})")
RAW Paste Data