fork(1) download
  1. import sys, math
  2.  
  3. def lower_hull(pts):
  4. pts = sorted(pts) # sort by x, then y
  5. hull = []
  6. for p in pts:
  7. while len(hull) >= 2:
  8. x1, y1 = hull[-2]
  9. x2, y2 = hull[-1]
  10. x3, y3 = p
  11. cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
  12. if cross <= 0: # not a left turn → pop
  13. hull.pop()
  14. else:
  15. break
  16. hull.append(p)
  17. return hull
  18.  
  19. def main():
  20. data = [s for s in sys.stdin.read().strip().split()]
  21. if not data:
  22. return
  23. it = iter(data)
  24. n = int(next(it))
  25. pts = [(int(next(it)), int(next(it))) for _ in range(n)]
  26.  
  27. hull = lower_hull(pts)
  28.  
  29. perim = 0.0
  30. for i in range(len(hull) - 1):
  31. x1, y1 = hull[i]
  32. x2, y2 = hull[i + 1]
  33. perim += math.hypot(x2 - x1, y2 - y1)
  34.  
  35. # round to nearest integer, .5 rounds up
  36. ans = int(math.floor(perim + 0.5))
  37. print(ans)
  38.  
  39. if __name__ == "__main__":
  40. main()
  41.  
Success #stdin #stdout 0.09s 14156KB
stdin
Standard input is empty
stdout
Standard output is empty