Codeforces Round#633(Div。2)C. Powered Addition(贪心)

ポータル

トピック:

ここに画像の説明を挿入
配列。T(秒)で配列の任意の要素にquick(2、T-1)を追加して、配列を
減少しないシーケンスに何秒変更できるか尋ねることができます。

アイデア:

前のものとの最大の違いを探してみてください、彼に会うのに数秒かかります、彼は他のことをすることができます。

コード:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<x<<endl
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//::iterator it;
ll a[MAXN];
ll b[MAXN];
ll quick(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a;
        a=a*a;
        b/=2;
    }
    return ans;
}
int main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
            ll k=-999;
        for(int i=2;i<=n;i++){
            if(a[i]<a[i-1]){
                k=max(k,a[i-1]-a[i]);
                a[i]=a[i-1];
            }
        }
        if(k==-999||n==1){
            cout<<0<<endl;
            continue;
        }
        ll T=1;
        ll sum=0;
        while(1){
            ll ppp=quick(2,T-1);
            if(sum+ppp>=k)break;
            sum+=ppp;
            T++;
        }
        cout<<T<<endl;
    }
    return 0;
}
/*

*/

 
 
元の記事を191件公開 賞賛17件 30,000回以上の閲覧

おすすめ

転載: blog.csdn.net/weixin_44091178/article/details/105482161