hiho week 209 register

Ended

Participants:113

Verdict:Accepted
Score:100 / 100
Submitted:2018-07-06 15:13:22

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
map<int, int> f;
int cal(int n){
    if(f.end() == f.find(n)) {
        int s;
        if(n % 2 == 0) s = cal(n / 2);
        else if(n == 1) s = 1;
        else s = min(cal(n - 1), cal(n + 1)) + 1;
        f[n] = s;
    }
    return f[n];
}
int main() {
    int n;
    scanf("%d", &n);
    int res = cal(n);
    printf("%d\n", res);
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX