hihoCoder #1498.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小时再复制一个机器人,要求出完成工作花费的最少时间。

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

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

 

代码:

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

 



 

 

转载于:https://www.cnblogs.com/ZERO-/p/7129105.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值