Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import dist
- data = open('27B.txt').readlines()
- cluster = [[], [], []]
- d = dict()
- for e in data:
- s = e.replace(',', '.').split()
- x, y = map(float, s[:2])
- type = s[2]
- d[(x, y)] = type
- if x > 22:
- cluster[0].append((x, y))
- elif y > 22:
- cluster[1].append((x, y))
- else:
- cluster[2].append((x, y))
- centroid = []
- for i in range(3):
- best_rst = 100000000000
- best_c = -1
- for c in cluster[i]:
- rst = 0
- for e in cluster[i]:
- rst += dist(c, e)
- if rst < best_rst:
- best_rst = rst
- best_c = c
- centroid.append(best_c)
- answ1 = 1000000000000
- for i in range(3):
- for a in cluster[i]:
- for b in cluster[i]:
- if a != b and d[a][0] == 'Z' and d[a][2:] == 'I' and d[b][0] == 'Z' and d[b][2:] == 'I':
- answ1 = min(answ1, dist(a, b))
- print(int(answ1 * 10000))
- amount = []
- for i in range(3):
- cnt = 0
- for e in cluster[i]:
- if d[e][0] == 'Z' and d[e][2:] == 'I':
- cnt += 1
- amount.append(cnt)
- print(amount)
- print(int(dist(centroid[0], centroid[2]) * 10000))
Advertisement
Add Comment
Please, Sign In to add comment