nq1s788

27 разные типы звезд

Jun 6th, 2026
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from math import dist
  2. data = open('27B.txt').readlines()
  3. cluster = [[], [], []]
  4. d = dict()
  5. for e in data:
  6.     s = e.replace(',', '.').split()
  7.     x, y = map(float, s[:2])
  8.     type = s[2]
  9.     d[(x, y)] = type
  10.     if x > 22:
  11.         cluster[0].append((x, y))
  12.     elif y > 22:
  13.         cluster[1].append((x, y))
  14.     else:
  15.         cluster[2].append((x, y))
  16. centroid = []
  17. for i in range(3):
  18.     best_rst = 100000000000
  19.     best_c = -1
  20.     for c in cluster[i]:
  21.         rst = 0
  22.         for e in cluster[i]:
  23.             rst += dist(c, e)
  24.         if rst < best_rst:
  25.             best_rst = rst
  26.             best_c = c
  27.     centroid.append(best_c)
  28. answ1 = 1000000000000
  29. for i in range(3):
  30.     for a in cluster[i]:
  31.         for b in cluster[i]:
  32.             if a != b and d[a][0] == 'Z' and d[a][2:] == 'I' and d[b][0] == 'Z' and d[b][2:] == 'I':
  33.                 answ1 = min(answ1, dist(a, b))
  34. print(int(answ1 * 10000))
  35. amount = []
  36. for i in range(3):
  37.     cnt = 0
  38.     for e in cluster[i]:
  39.         if d[e][0] == 'Z' and d[e][2:] == 'I':
  40.             cnt += 1
  41.     amount.append(cnt)
  42. print(amount)
  43. print(int(dist(centroid[0], centroid[2]) * 10000))
Advertisement
Add Comment
Please, Sign In to add comment