hihocode——#1498 : Diligent Robots

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/gxh27954/article/details/69788317

http://hihocoder.com/problemset/problem/1498

#1498 : Diligent Robots

時間限制:10000ms
單點時限:1000ms
內存限制:256MB

描述

There are N jobs to be finished. It takes a robot 1 hour to finish one job.

At the beginning you have only one robot. Luckily a robot may build more robots identical to itself. It takes a robot Q hours to build another robot.  

So what is the minimum number of hours to finish N jobs?

Note two or more robots working on the same job or building the same robot won't accelerate the progress.

輸入

The first line contains 2 integers, N and Q.  

For 70% of the data, 1 <= N <= 1000000  

For 100% of the data, 1 <= N <= 1000000000000, 1 <= Q <= 1000

輸出

The minimum number of hours.

樣例輸入
10 1
樣例輸出
5

假設生了k次機器人,那麼時間就是n/2^k+k*q

n,q已知,那麼枚舉k就行~~

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
typedef long long LL;
int main()
{
    LL n,q;
    cin>>n>>q;
    if(n<=2*q)
    {
        cout<<n<<endl;
    }
    else
    {
        LL ans=1e12;
        for(LL k=0; ; k++)
        {
            LL hour = 1LL<<k;
            if(hour>n)
            {
                break;
            }
            if(n%hour==0)
            {
                ans=min(ans,(n/hour)+k*q);
            }
            else
            {
                ans=min(ans,(n/hour)+1+k*q);
            }
        }
        cout<<ans<<endl;
    }

}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章