본문 바로가기
알고리즘/수학

1057 토너먼트

by tryotto 2020. 2. 22.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <math.h>
 
int main() {
    int n, a, b;
    scanf("%d %d %d"&n, &a, &b);
 
    if (a > b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
 
    int two = 1, cnt = 1;
    while (1) {
        int tmpA = a / two;
        if (a % two > 0)
            tmpA++;
 
        int tmpB = b / two;
        if (b % two > 0)
            tmpB++;
        
        if ((tmpA + 1 == tmpB) && (tmpB % 2 == 0)) {
            printf("%d", cnt);
            break;
        }
 
        two *= 2;
        cnt++;
    }
}
cs



발상이 좀 필요했던 문제.


'알고리즘 > 수학' 카테고리의 다른 글

2875 대회 or 인턴  (0) 2020.03.12
1789 수들의 합  (0) 2020.02.29