[백준] 1057번 토너먼트 / C++
#문제
#풀이
#include <iostream>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, jm, hs;
cin >> n >> jm >> hs;
int round = 0;
while (jm != hs)
{
jm = (jm + 1) / 2;
hs = (hs + 1) / 2;
round++;
}
cout << round;
return 0;
}
#정리
나눗셈 연산을 사용. 지민과 한수의 번호가 같아질 때 까지 (jm + 1) / 2, (hs + 1) / 2 연산을 진행하여 해결할 수 있는 문제.
Enjoy Reading This Article?
Here are some more articles you might like to read next: