Skip to content

[PGS] 예상대진표 - #60

Open
been12151 wants to merge 12 commits into
mainfrom
week3/예상대진표

Hidden character warning

The head ref may contain hidden characters: "week3/\uc608\uc0c1\ub300\uc9c4\ud45c"
Open

[PGS] 예상대진표#60
been12151 wants to merge 12 commits into
mainfrom
week3/예상대진표

Conversation

@been12151

Copy link
Copy Markdown
Owner

🍪 문제 이름

Resolve: 예상 대진표

🍊 문제 정의

input

  • n : 참가자 수 (2 이상 2^20 이하, 항상 2의 거듭제곱)
  • a : 참가자 a의 번호
  • b : 참가자 b의 번호

output

  • a와 b가 몇 번째 라운드에서 처음 만나는지

예시

n a b result
8 4 6 3

🍑 알고리즘 설계

매 라운드마다 각 참가자의 번호를 (번호 + 1) // 2로 줄여 다음 라운드에서의 번호로 갱신.
a와 b가 같아지는 순간이 처음으로 같은 조에 속해 대결하는 라운드이므로, 같아질 때까지 반복하며 라운드 수를 카운트.

def solution(n, a, b):
    answer = 0
    while a != b:
        a = (a + 1) // 2
        b = (b + 1) // 2
        answer += 1
    return answer

🥝 최악 수행 시간 복잡도

  • O(log n)
  • 매 라운드마다 번호가 절반으로 줄어들어 최대 log₂n번 반복 후 a와 b가 같아짐

🍰 특이 사항 (Optional)

(번호 + 1) // 2로 다음 라운드 번호를 구하는 부분에서, 홀수 번호일 때 올림 처리가 자연스럽게 됨 (math.ceil(a / 2)와 동일).

@been12151
been12151 requested review from gayo73 and yangyeeeun July 9, 2026 02:07
@been12151 been12151 self-assigned this Jul 9, 2026
@been12151 been12151 linked an issue Jul 9, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PGS] 예상 대진표 / level 2

2 participants