https://school.programmers.co.kr/learn/courses/30/lessons/12985
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
class Command
{
public:
Command(const int& a, const int& b)
: _a(a), _b(b)
{
}
const bool operator() ()
{
return _a != _b;
}
public:
void vs()
{
_a = (_a + 1) >> 1;
_b = (_b + 1) >> 1;
}
private:
int _a;
int _b;
};
int solution(int n, int a, int b)
{
int answer = 0;
Command cmd(a, b);
while (cmd())
{
cmd.vs();
++answer;
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] Lv 2. N개의 최소공배수 (0) | 2023.06.01 |
---|---|
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 점프와 순간 이동 (0) | 2023.05.31 |
[Programmers] (탐욕법(Greedy)) Lv 2. 구명보트 (0) | 2023.05.30 |
[Programmers] (완전탐색) Lv 2. 카펫 (0) | 2023.05.25 |
[Programmers] Summer/Winter Coding(~2018) Lv 2. 영어 끝말잇기 (0) | 2023.05.23 |
댓글