Update Files

Codeforce 1606.B Update Files

题解

有n台电脑,k根数据线,两台电脑间可以通过连线传文件。最开始只有一台电脑上有,要求最后n台电脑都要有文件。仔细观察会发现文件能传输的总数是呈指数增长的。
在k足够的情况下,当前有文件的电脑数为2^x次方。
当k不足够时,每单位时间内所能增加的数量即为k。

#include<iostream>
#inlucde<cmath>
#define ll long long
using namespace std;
int t;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    cin>>t;
    while(t--){
        int n,k,ans=0;
        cin>>n>>k;
        if(n>=k){
            ans=log2(n)+((n-1)&n)?1:0;
        }
        else {
            long long sec=log2(k)+1;
            ans=sec;
            if((1ll<<sec)<n){
                ans+=((n-(1ll<<sec))/k)+((n-(1ll<<sec))%k?1:0);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
posted @ 2021-10-30 12:57  Chilyyy  阅读(274)  评论(0)    收藏  举报