Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #B https://inf-ege.sdamgia.ru/problem?id=70554
- from math import dist
- data = open('demo_2025_27_Б.txt').readlines()
- cluster = [[], [], []]
- for i in range(1, len(data)):
- data[i] = list(map(float, data[i].replace(',', '.').split()))
- if data[i][1] < 4:
- cluster[0].append(data[i])
- elif data[i][0] > 5:
- cluster[1].append(data[i])
- else:
- cluster[2].append(data[i])
- answ = []
- for i in range(3):
- centroid = -1
- rst = 1000000000000
- for c in cluster[i]:
- sm = 0
- for x in cluster[i]:
- sm += dist(c, x)
- if sm < rst:
- centroid = c
- rst = sm
- answ.append(centroid)
- print(int(((answ[0][0] + answ[1][0] + answ[2][0]) / 3.0) * 10000), int(((answ[0][1] + answ[1][1] + answ[2][1]) / 3.0) * 10000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement