首页 > 代码库 > hihoCoder1498-Diligent Robots

hihoCoder1498-Diligent Robots

#1498 : Diligent Robots

Time Limit:10000ms
Case Time Limit:1000ms
Memory Limit:256MB

Description

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.

Input

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

Output

The minimum number of hours.

Sample Input
10 1
Sample Output
5

题意就是机器人完成工作,机器人可以做两种事,一个是机器人可以花一小时完成一项工作,另一个是机器人花Q小时再复制一个机器人,要求出完成工作花费的最少时间。

可以先把所有要复制的先复制完,然后再完成工作。

注意两个或两个以上的机器人在同一个工作或复制相同的机器人不会加速进展。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,m,a,b,ans,cnt;
    while(~scanf("%lld%lld",&n,&m)){
        a=2;b=1;ans=n;                             //最初假设复制了一次,两个机器人
        while(a<n){                            
            if(n%a==0)                             //判断一下是否整除工作量,不整除就为一个小时
               cnt=0;
            else
                cnt=1;
            ans=min(ans,b*m+n/a+cnt);              
            a*=2;                                  //几个机器人
            b++;                                   //复制几次
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

没了==

 

hihoCoder1498-Diligent Robots