Phoenix and Science [CF1348 D] (Mathematics, Laws)

D. Phoenix and Science

CF1348 D
title meaning:
cell division, the number on the first day is 1 11 . There can be0 0every day after that0 ~Current number of cells Current number of cellsWhen before the fine cells a number of cells inmmm is split intom 2 \frac{m}{2}2m. Then every cell will be +1 +1 that night+ 1 .
Q becomesnnThe minimum number of days for n cells.

Idea:
Observe the sample and push it with your hand.
Find:For the total, m ⟹ m 2 m\Longrightarrow\frac{m}{2}m2mDoes not change the final sum sums u m will only increase the night addendans ansa n s
The largest addend ans ansa n s growth rate is2 x 2^x2x increases exponentially, and the number of days is the smallest at this time.
But note that for the daily addendans ansFor a n s , this is a non-strictly increasing sequence, and the output value is the addendans ansThe difference of a n s (greater than or equal to 0).
When calculating, the addend ans ans of the last daya n s isn − 2 i + 1 n-2^i+1n2i+1 It is calculated that it may be less than theans ans of theprevious daya n s , remember to deal with the final day's addendans ansa n s is greater than or equal to the day before

LL ans[100];
int main(){
    
    
    int t;
    cin>>t;
    LL n,nw,pre,tt;
    while(t--){
    
    
        cin>>n;
        ans[1]=1;
        nw=1;tt=2;
        for(int i=1;i<=50;i++){
    
    
            ans[i+1]=tt;
            if(tt*2-1>=n){
    
    
                ans[i+1]=n-tt+1;
                nw=i;
                break;
            }
            tt*=2ll;
        }
        cout<<nw<<endl;
        if(ans[nw+1]<ans[nw]){
    
    
            tt=ans[nw+1]+ans[nw];
            ans[nw]=tt/2;
            ans[nw+1]=tt/2+tt%2;
        }
        for(int i=2;i<=nw+1;i++){
    
    
            cout<<ans[i]-ans[i-1]<<" ";
        }
        cout<<endl;
    }
}

Guess you like

Origin blog.csdn.net/weixin_44986601/article/details/105932456