EPS/2024/03/25-03-24/c.py

36 lines
903 B
Python
Raw Permalink Normal View History

2024-04-15 13:45:30 +02:00
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
p1 = points[0]
d_min = float("inf")
p_min = -2
def dist(pa, pb):
return (pb[0]-pa[0])*(pb[0]-pa[0]) + (pb[1]-pa[1])*(pb[1]-pa[1])
i2 = min((i for i in range(1, n)), key=lambda x:dist(p1, points[x]))
p2 = points[i2]
def aligned(p1, p2, p3):
# Extract coordinates of points
x1, y1 = p1
x2, y2 = p2
x3, y3 = p3
# Calculate slopes of lines formed by pairs of points
slope1 = (y2 - y1) / (x2 - x1) if x2 - x1 != 0 else float('inf')
slope2 = (y3 - y2) / (x3 - x2) if x3 - x2 != 0 else float('inf')
# Check if slopes are equal (i.e., points are aligned)
return slope1 == slope2
for i in range(1, n):
if i == i2:
continue
d = dist(p1, points[i])
if d <= d_min and not aligned(p1, p2, points[i]):
d_min = d
p_min = i
print(1, i2+1, p_min+1)