hiho week 209 register

Ended

Participants:113

Verdict:Accepted
Score:100 / 100
Submitted:2018-07-05 21:16:41

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
24
25
26
27
#include <iostream>
#include <map>
using namespace std;
map<int, int> f;
int calc(int n) {
  if (f.find(n) == f.end()) {
    int s;
    if (n % 2 == 0) {
      s = calc(n / 2);
    } else if (n == 1) {
      s = 1;
    } else {
      s = min(calc(n - 1), calc(n + 1)) + 1;
    }
    f[n] = s;
  }
  return f[n];
}
int main() {
  int n;
  cin >> n;
  cout << calc(n);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX