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
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 10178 - 할로윈의 사탕 [python] (0) | 2023.03.28 |
---|---|
[BOJ/백준] 9950 - Rectangles [python] (0) | 2023.03.28 |
[BOJ/백준] 9924 - The Euclidean Algorithm [python] (0) | 2023.03.28 |
[BOJ/백준] 9907 - ID [python] (0) | 2023.03.28 |
[BOJ/백준] 9848 - Gift [python] (0) | 2023.03.28 |