import sys
import math
from stars import __stars
__stars() # Инициализация задачи
def read_points_from_file(filename="stars.txt"):
pts = []
with open(filename, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
parts = line.split()
x_str = parts[0].replace(",", ".")
y_str = parts[1].replace(",", ".")
x = float(x_str)
y = float(y_str)
pts.append((x, y))
return pts
def split_clusters(points):
sorted_points = sorted(points, key=lambda p: p[0])
max_gap = 0
split_index = 0
for i in range(len(sorted_points) - 1):
gap = sorted_points[i+1][0] - sorted_points[i][0]
if gap > max_gap:
max_gap = gap
split_index = i
threshold = (sorted_points[split_index][0] + sorted_points[split_index+1][0]) / 2
cluster1 = []
cluster2 = []
for point in points:
if point[0] <= threshold:
cluster1.append(point)
else:
cluster2.append(point)
return cluster1, cluster2
def find_center(cluster):
if not cluster:
return None
min_sum_dist = float('inf')
center = None
for p in cluster:
sum_dist = 0
for q in cluster:
if p != q:
dist = math.sqrt((p[0] - q[0])**2 + (p[1] - q[1])**2)
sum_dist += dist
if sum_dist < min_sum_dist:
min_sum_dist = sum_dist
center = p
return center
def main():
points = read_points_from_file("stars.txt")
cluster1, cluster2 = split_clusters(points)
center1 = find_center(cluster1)
center2 = find_center(cluster2)
Px = (center1[0] + center2[0]) / 2
Py = (center1[1] + center2[1]) / 2
print(int(Px * 10000))
print(int(Py * 10000))
if __name__ == "__main__":
main()