weixin_52463018 2021-11-15 19:12 采纳率: 100%
浏览 21
已结题

满二叉树的应用(c++)

img

  • 写回答

1条回答 默认 最新

  • Clarence Liu 2021-11-15 19:28
    关注
    
    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        int t;
        ll x, y;
        cin >> t;
        while(t--){
            cin >> x >> y;
            if(x > y) swap(x, y);
            ll ans = 0;
            while((ll)(log2(x)) != (ll)(log2(y))){
                y >>= 1;
                ans += 1;
            }
            while(x != y){
                x >>= 1;
                y >>= 1;
                ans += 2;
            }
            cout << ans << '\n';
        }
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月31日
  • 已采纳回答 12月23日
  • 创建了问题 11月15日