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

#문제

백준 1057번 토너먼트

#풀이

#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:

  • [백준] 1037번 최소공배수 / C++
  • [백준] 1940번 주몽 / C++
  • [백준] 1934번 최소공배수 / C++
  • [백준] 11050번 이항 계수 1 / C++
  • [백준] 15652번 N과 M (4) / C++