🖥 시작하며
수학 문제다.
토너먼트를 직접 그려보면서 접근하면 더 잘 이해할 수 있다. 

⚙️ 코드
import sys input = sys.stdin.readline def solution(a, b): round = 0 # 라운드 0부터 시작 # a와 b가 같으면 이전 라운드에서 만났다는 말과 같음 while a != b: round += 1 a = (a + 1) // 2 b = (b + 1) // 2 return round if __name__ == "__main__": N, A, B = map(int, input().split()) result = solution(N, A, B) print(result)
#include <iostream> using namespace std; int solution(int n, int a, int b) { int round = 0; while (a != b) { round++; a = (a + 1) / 2; b = (b + 1) / 2; } return round; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, A, B; cin >> N >> A >> B; int result = solution(N, A, B); cout << result << "\n"; return 0; }

![[백준] 1057 - 토너먼트](https://reo91004.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb4dac9d0-810c-47c4-800c-0ca10b8d0529%2F59a6b96b-ea1e-4699-b4a7-7d4639037809%2Fi_baekjoon.png?table=block&id=11ad2f02-2ff6-802a-9550-f6420844bcbf&cache=v2)
![[백준] 1057 - 토너먼트](https://reo91004.notion.site/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fb4dac9d0-810c-47c4-800c-0ca10b8d0529%2F429a23f3-afb3-4642-a11b-60f2076a61f6%2Fw_baekjoon.jpg?table=block&id=11ad2f02-2ff6-802a-9550-f6420844bcbf&cache=v2)

댓글