Algorithm/PS
[BOJ/백준] 9945 - Centroid of Point Masses [python]
chanwoong1
2023. 3. 28. 12:23
728x90
9945번: Centroid of Point Masses
Input will be sets of points. Each set will be specified by the number of points n in the set followed by n lines of three numbers representing xi, yi, and mi values for i = 1 to n. All these numbers will be integers from 1 to 5000. That is, n will be from
www.acmicpc.net
문제 풀이
무게 중심을 구해주기 위해 xi * m의 합을 m의 합으로 나누어주었다.
정답 코드
cnt = 1
while True :
N = int(input())
if N < 0 : break
sum_x, sum_y, sum_m = 0, 0, 0
for _ in range(N) :
x, y, m = map(float, input().split())
sum_x += x * m
sum_y += y * m
sum_m += m
print("Case {:d}: {:.2f} {:.2f}".format(cnt, sum_x / sum_m, sum_y / sum_m))
cnt += 1
input()
728x90