본문 바로가기

Programming/BaekJoon

[C++] 백준 1057번 : 토너먼트


https://www.acmicpc.net/problem/1057




#include <iostream>

#include <math.h>


using namespace std;


int main() {


int n;

int m1, m2;

cin >> n >> m1 >> m2;


n--;

m1--;

m2--;


int tmp = 0;

while (1) {

if (n >= 2)

{

n /= 2;

tmp++;

}

else

break;

}


int round = tmp + 1;

int result = 0, flag = 0;

while (flag != 1) {

(m1 / (int)pow(2, tmp)) == (m2 / (int)pow(2, tmp)) ? result++ : flag = 1;

tmp--;

}

round -= result;


cout << round << endl;


}