Programming/Programmers
[프로그래머스] 양궁대회 (Python)
데이터현
2022. 1. 23. 15:59
https://programmers.co.kr/learn/courses/30/lessons/92342
코딩테스트 연습 - 양궁대회
문제 설명 카카오배 양궁대회가 열렸습니다. 라이언은 저번 카카오배 양궁대회 우승자이고 이번 대회에도 결승전까지 올라왔습니다. 결승전 상대는 어피치입니다. 카카오배 양궁대회 운영위원
programmers.co.kr
combinations_with_replacement 를 활용해서 풀었다
나의 풀이
from itertools import combinations_with_replacement
from collections import Counter
def solution(n, info):
max_score = 0
answer = []
for i in combinations_with_replacement(range(11), n):
a_score, l_score = 0,0
cnt = Counter(i)
for i in range(11):
if info[10-i] == 0 and cnt[i] == 0:
continue
if info[10-i] >= cnt[i]:
a_score += i
else:
l_score += i
if max_score < (l_score - a_score) : # 스코어가 더 크다면
max_score = (l_score - a_score)
answer = cnt
elif max_score == (l_score - a_score) and max_score !=0: # 스코어가 같다면
if answer == [] :
answer = cnt
else:
for i in range(11):
if answer[i] == 0 and cnt[i] == 0:
continue
if answer[i] < cnt[i]:
answer = cnt
break
elif answer[i] > cnt[i]:
break
if answer == []:
return [-1]
else:
temp = answer
answer = [0]*11
for i in range(11):
answer[10-i] = temp[i]
return answer