• 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
    ",ans);
    18     }
    19     return 0;
    20 }


     

  • 相关阅读:
    docker镜像加速
    Job for network.service failed because the control process exited with error code
    python单例模式
    python实现简单算法
    Python母版使用
    Python中自定义filter用法
    linux挂载Windows共享文件夹
    重写用户模型时报错AttributeError: type object ‘自定义类’ has no attribute ‘USERNAME_FIELD’
    2020年3月10日 socket2
    2020年2月27日 socket 1
  • 原文地址:https://www.cnblogs.com/ZERO-/p/7129105.html
Copyright © 2020-2023  润新知