hihoCoder #1498 : Diligent Robots【数学】

简介: #1498 : Diligent Robots 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There are N jobs to be finished.

#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 }

 

 

目录
相关文章
|
2月前
|
安全 中间件 Shell
AWD的那些事
AWD的那些事
24 0
|
10月前
|
NoSQL 安全 Redis
Bugku S3 AWD排位赛-3(带你入门awd流程)
Bugku S3 AWD排位赛-3(带你入门awd流程)
639 1
|
12月前
|
算法 数据安全/隐私保护 计算机视觉
CTF杂项提纲
CTF杂项提纲
58 2
|
12月前
|
监控 安全 中间件
CTF/AWD竞赛标准参考书+实战指南:《AWD特训营》
CTF/AWD竞赛标准参考书+实战指南:《AWD特训营》
|
机器学习/深度学习 人工智能 自然语言处理
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型(1)
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型
128 0
|
机器学习/深度学习 Web App开发 人工智能
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型(2)
7 Papers & Radios | 中国天眼FAST登Nature封面;MIT提出可出题、做题、评分模型
248 0
|
自然语言处理
每日一题——验证外星语词典
每日一题——验证外星语词典
69 0
每日一题——验证外星语词典
|
算法 决策智能 Windows
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
293 0
【论文阅读】(2017)The late acceptance Hill-Climbing heuristic
|
机器学习/深度学习 运维
|
存储 算法 调度
【CCCC】PAT : 团体程序设计天梯赛-练习集 L2 答案,题解,附代码
【CCCC】PAT : 团体程序设计天梯赛-练习集 L2 答案,题解,附代码
385 0