GYM 100030 D.Broadcasting(水~)

来源:互联网 发布:淘宝收藏店铺上限 编辑:程序博客网 时间:2024/06/08 09:40

Description
n台电脑,两两相连可以互传数据,每台电脑每秒可以同时给k台电脑传数据,现在只有1台电脑有数据,问最少需要几秒使得所有电脑都有该数据
Input
两个整数n和k分别表示电脑数量和一台电脑每秒最多可以传输数据的电脑数(1<=n,k<=1e9)
Output
输出使得是所有电脑都有数据所需的最少时间
Sample Input
4 1
Sample Output
2
Solution
答案即为满足(k+1)^x>=n的最小x
Code

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 1111int main(){    freopen("input.txt","r",stdin);    freopen("output.txt","w",stdout);    ll k,n;    while(~scanf("%I64d%I64d",&n,&k))    {        int ans=0;        ll temp=1;        while(temp<n)        {            temp*=(k+1);            ans++;        }        printf("%d\n",ans);    }    return 0;}
0 0
原创粉丝点击