hiho week 209 register

Ended

Participants:113

Verdict:Accepted
Score:100 / 100
Submitted:2018-07-02 15:58:36

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<bits/stdc++.h>
using namespace std;
#define int long long
int f[100],ans;
void dfs(int x){
    if(x==0) return;
    int zh=lower_bound(f+1,f+31+1,x)-f;
    int zh1=zh-1;
    x=min(x-f[zh1],f[zh]-x);
    ans++;
    dfs(x);
}
signed main(){
    f[0]=1; f[1]=2;
    for(int i=2;i<=31;i++) f[i]=f[i-1]*2;
    int x; cin>>x;
    dfs(x);
    cout<<ans;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX