首页 > 代码库 > HihoCoder - 1498 Diligent Robots
HihoCoder - 1498 Diligent 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.
InputThe 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
OutputThe minimum number of hours.
Sample Input
10 1
Sample Output
5
解题思路:
被签到题卡了半天也是日了狗了,直接暴力就能过结果非要去推公式求导,结果还求错了。。。
#include<iostream>#include<cmath>using namespace std;#define ll long longint 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。