hihoCoder #1498 : Diligent Robots【数学】

#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
 

思路分析

首先,如果要复制机器,就要尽早复制,因为尽早复制可以尽早投入生产。
我的纠结点在于,复制的最后一轮,会不会有一部分机器人在复制,其他机器人在工作?
通过严谨的证明说明是不会的。

以下证明过程参考一位大神的,很严谨的证明,I love it!QAQ


因为我上面的证明里得到了“T>2qm”这个临界条件,因此在代码里可以直接使用。详解代码中已给出!

下面给出AC代码:

 1 #include <bits/stdc++.h>
 2 typedef long long ll;
 3 using namespace std;
 4 int main()
 5 {
 6     ll n,q;
 7     cin>>n>>q;//n表示任务总数,q表示生产一次机器人需要的时间
 8     ll m=1,r=0;//m表示初始时机器人的数量,r表示生产次数
 9     while(n>2*m*q)//根据结论,机器人应当全部复制
10     {
11         m<<=1;//倍增操作
12         r++;
13     }
14     ll t=q*r+n/m;//总时间为生产机器人所花费的时间q*r+任务数与机器人的比值(每个机器人单位时间生产单位价值的产品)
15     if(n%m)//不能整除的话说明t++;
16         t++;
17     cout<<t<<endl;
18     return 0;
19 }
原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/7136061.html