Skip to content

Commit

Permalink
양궁대회 문제 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeVicTech committed Feb 11, 2023
1 parent 77fb75e commit c1d3dd4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions 비트마스킹/양궁대회.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# https://school.programmers.co.kr/learn/courses/30/lessons/92342

# 이진수를 활용한 비트마스킹 기법을 처음 배워서 사용했다.
# 이진수를 사건이 일어난 경우와 일어나지 않는 경우를 각각 1과 0으로 매칭할 수 있다는 것을 배움

def solution(n, info):
answer = [0] * 11
tmp = [0] * 11
maxDiff = 0

for subset in range(1<<10):
cnt = 0
ryan = 0
appeach = 0
for i in range(11):
if subset & (1<<i):
ryan += 10-i
tmp[i] = info[i] + 1
cnt += tmp[i]
else:
tmp[i] = 0
if info[i]:
appeach += 10-i

if cnt > n:
continue

tmp[10] = n - cnt

if ryan-appeach == maxDiff:
for i in reversed(range(11)):
if tmp[i] > answer[i]:
answer = tmp[:]
break
if tmp[i] < answer[i]:
break

elif ryan-appeach > maxDiff:
maxDiff = ryan-appeach
answer = tmp[:]

if maxDiff == 0:
answer = [-1]

return answer

solution(5,[2,1,1,1,0,0,0,0,0,0,0])

0 comments on commit c1d3dd4

Please sign in to comment.