| 比赛 | 
    EYOI暨SBOI暑假快乐赛2nd | 
    评测结果 | 
    WWWWWWWWWW | 
    | 题目名称 | 
    幂次计算 | 
    最终得分 | 
    0 | 
    | 用户昵称 | 
    该账号已注销 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2022-06-26 10:20:40 | 
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n;
int ans=0x3f3f3f3f;
int dfs(int x,int u){
    if(x==1)
    {
        ans=min(ans,u);
        return 0;
    }
    if(x%2==1)
    {
        if(u+1>ans)
        return 0;
        dfs(x+1,u+1);
        dfs(x-1,u+1);
    }
    if(x%2==0)
    {
        if(u+1>ans)
        return 0;
        dfs(x/2,u+1);
    }
    return 0;
}
int main(){
    freopen("mico.in","r",stdin);
    freopen("mico.out","w",stdout);
    while(cin>>n)
    {
        if(n==0)
        return 0;
        ans=0x3f3f3f3f;
        if(n==1)
        {
            cout<<0<<endl;
            continue;
        }
        dfs(n,0);
        cout<<ans<<endl;
    }
    return 0;
}