Powered Addition

C - Powered Addition

要想到的东西是,每一个数只能增不能减,而且入宫前面的数字增加,后面的数字也会受到影响,即使原来是满足条件的,操作后也不一定就满足。要找到前后差别最大值,然后进行一番操作。

而且要注意的是,每秒之间的操作可以叠加产生效果。

写题时要注意分析数字之间的关系。

// Created by CAD on 2020/4/13.
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f
#define ll long long
using namespace std;

const int maxn=1e5+5;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;cin>>t;
    while(t--){
        int n,x;cin>>n;
        int dis=0,maxx=-inf;
        for(int i=1;i<=n;++i){
            cin>>x;
            dis=max(dis,maxx-x);
            maxx=max(maxx,x);
        }
        int ans=0,bj=1;
        while(dis>0){
            ans++;
            dis-=bj;
            bj*=2;
        }
        cout<<ans<<"\n";
    }
    return 0;
}
posted @ 2020-04-13 21:52  caoanda  阅读(270)  评论(0编辑  收藏  举报