BOJ - 13708 - 모든 점을 포함하는 원
Updated:
import sys
import math
def getDistance(p1, p2):
return (math.pow(p1[0] - p2[0], 2) + math.pow(p1[1] - p2[1], 2))
def solution():
N = int(sys.stdin.readline())
standard = [0, 0]
point = []
for _ in range(N):
x, y = map(float, sys.stdin.readline().split())
standard[0] += x
standard[1] += y
point.append([x, y])
standard[0] /= N
standard[1] /= N
step = 0.1
ret = 0
for i in range(30000):
ret = 0
number = 0
for j in range(N):
distance = getDistance(standard, point[j])
if distance > ret:
number = j
ret = distance
standard[0] += (point[number][0] - standard[0]) * step
standard[1] += (point[number][1] - standard[1]) * step
step *= 0.999
print("%0.2f"%(math.sqrt(ret) * 2))
solution()
https://www.acmicpc.net/problem/13708
Leave a comment