https://school.programmers.co.kr/learn/courses/30/lessons/152996
from collections import Counter
from itertools import combinations
def solution(weights):
answer = 0
# 시소 거리 경우의 수
dis_li = [(1, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3)]
# 무게 카운트
counter = dict(Counter(weights))
# 중복 제거한뒤 2명 경우의 수
unique_weights = list(combinations(sorted(counter.keys()), 2))
for a, b in unique_weights:
for x, y in dis_li:
# 비율이 맞으면 각각의 명 수를 곱해서 더함
if a*y == b*x:
answer += counter[a]*counter[b]
break
# 같은 무게가 2명 이상이면 그 경우 더해줌
for a, b in counter.items():
if b >= 2:
answer += b*(b-1)//2
return answer'코딩테스트 > 코딩테스트 문제풀이' 카테고리의 다른 글
| [Python] 프로그래머스 <무인도 여행> (0) | 2025.07.25 |
|---|---|
| [Python] 프로그래머스 <야근 지수> (0) | 2025.07.25 |
| [Python] 백준 <1261-알고스팟> (0) | 2025.07.23 |
| [Python] 백준 <16472-고냥이> (0) | 2025.07.23 |
| [Python] 백준 <1062-가르침> (0) | 2025.07.23 |