1338A. Powered Addition (thinking)

Ignore the nature of binary, that is, the power of 2 can be combined into any number, so for each number, you can first greedily calculate the number of steps that makes this number larger than the previous number, and then remove the extra steps before the bottom of the kettle.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+100;
ll a[maxn];
ll cal (ll a,ll b) {
    ll ans=1;
    ll num=a;
    while (b) {
        if (b&1) ans=ans*num;
        num=(num*num);
        b>>=1;
    }
    return ans;
}
int main () {
    int T;
    scanf("%d",&T);
    while (T--) {
        int N;
        scanf("%d",&N);
        ll Max=0;
        for (int i=1;i<=N;i++) scanf("%lld",&a[i]);
        for (int i=2;i<=N;i++) {
            if (a[i]>=a[i-1])
                continue;
            ll x=1;
            while (cal(2,x)-1<a[i-1]-a[i]) {
                x++;
            }
            a[i]+=cal(2,x)-1;
            a[i]=a[i-1];
            Max=max(Max,x);
        }
        printf("%lld\n",Max);
    }
}

 

Guess you like

Origin www.cnblogs.com/zhanglichen/p/12690625.html