fork download
  1. def distance(x1, y1, x2, y2):
  2. """Calculates the Euclidean distance between two points."""
  3. return ((x2 - x1)**2 + (y2 - y1)**2)**0.5
  4.  
  5. def calculate_stability(points):
  6. """Calculates the stability of a triumvirate."""
  7. distances = []
  8. for i in range(3):
  9. for j in range(i + 1, 3):
  10. distances.append(distance(points[i][0], points[i][1], points[j][0], points[j][1]))
  11. return max(distances) - min(distances)
  12.  
  13. def find_best_triumvirates(points):
  14. """Finds the best grouping of points into triumvirates."""
  15. n = len(points)
  16. triumvirates = []
  17. for i in range(0, n, 3):
  18. triumvirates.append([i, i + 1, i + 2])
  19. best_triumvirates = triumvirates
  20. best_score = sum(calculate_stability([points[j] for j in t]) for t in triumvirates)
  21.  
  22. # Implement a more efficient search algorithm here to find the optimal grouping
  23. # (e.g., brute force, greedy, or a more advanced optimization technique)
  24.  
  25. return best_triumvirates
  26.  
  27. def main():
  28. n = int(input())
  29. points = []
  30. for _ in range(n):
  31. x, y = map(int, input().split())
  32. points.append((x, y))
  33. best_triumvirates = find_best_triumvirates(points)
  34. for t in best_triumvirates:
  35. print(*t)
  36.  
  37. if __name__ == "__main__":
  38. main()
Success #stdin #stdout 0.04s 9856KB
stdin
9
26 28
22 1
4 26
6 28
21 15
14 14
3 2
20 22
21 10
stdout
0 1 2
3 4 5
6 7 8