전.py
[python] 백준 1057 토너먼트
jeonnew
2022. 1. 6. 18:53
728x90
https://www.acmicpc.net/problem/1057
1057번: 토너먼트
김지민은 N명이 참가하는 스타 토너먼트에 진출했다. 토너먼트는 다음과 같이 진행된다. 일단 N명의 참가자는 번호가 1번부터 N번까지 배정받는다. 그러고 난 후에 서로 인접한 번호끼리 스타를
www.acmicpc.net
n, a, b = map(int, input().split())
mn = min(a, b)
mx = max(a, b)
def func():
l = [i+1 for i in range(n)]
cnt = 1
while True:
j = len(l)//2
if len(l) == 2:
print(cnt)
break
next = []
for i in range(j):
if mn in l[2*i:2*i+2]:
if mx in l[2*i:2*i+2]:
print(cnt)
return
else:
next.append(mn)
else:
if mx in l[2*i:2*i+2]:
next.append(mx)
else:
next.append(l[2*i])
# 다음 라운드 진출 인원 담은 리스트
if len(l) % 2 == 1:
l = next + [l[len(l)-1]]
else:
l = next
cnt += 1
func()
반응형