kxcoze

tanya_lab_2

Sep 16th, 2022
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import random as r
  2. from math import sqrt
  3. dist = lambda x0, y0, x1, y1: sqrt((x1-x0)**2 + (y1-y0)**2)
  4.  
  5. def solve():
  6.     n = r.randint(5, 5)
  7.     s = []
  8.     for i in range(n):
  9.         s.append([r.randint(1, 1000), (r.randint(-10, 10), r.randint(-10, 10))])
  10.     print(*s)
  11.     s = sorted(s)
  12.     while len(s) > 1:
  13.         e = s.pop()
  14.         print(f'Max point is {e}')
  15.         ind = min([(dist(*e[1], *e_[1]), ind) for ind, e_ in enumerate(s)])[1]
  16.         s[ind][0] += e[0]
  17.         print(f'Nearest point is {s[ind]}')
  18.         s.sort()
  19.         print()
  20.     print(f'Finale point is {s[0]})')
  21.     return
  22.  
  23. print(solve())
Advertisement
Add Comment
Please, Sign In to add comment