码迷,mamicode.com
首页 > 其他好文 > 详细

HihoCoder - 1498 Diligent Robots

时间:2017-07-06 18:58:43      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:beginning   include   break   class   pre   not   code   math   robots   

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

解题思路:
被签到题卡了半天也是日了狗了,直接暴力就能过结果非要去推公式求导,结果还求错了。。。
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
int main()
{
    ll m,q,ans=0,i,t;
    cin>>m>>q;
    ll sum = 999999999;
    while(1){
        if(pow(2,ans)>m)
            break;
        t=ans*q+m/(pow(2,ans));
        int num = m/pow(2,ans);
        if(m-pow(2,ans)*num!=0)
            t++;
        sum = min(t,sum);
        ans++;
    }
    cout<<sum<<endl;
}

 

HihoCoder - 1498 Diligent Robots

标签:beginning   include   break   class   pre   not   code   math   robots   

原文地址:http://www.cnblogs.com/kls123/p/7127042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!