zoukankan      html  css  js  c++  java
  • 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 }


     

  • 相关阅读:
    随笔2
    随笔
    关于updateElement接口
    随笔1
    本地访问正常,服务器访问乱码 记录
    Redis (error) NOAUTH Authentication required.解决方法
    tomcat启动很慢 停留在 At least one JAR was scanned for TLDs yet contained no TLDs.
    微信公众号消息回复
    微信公众号 报token验证失败
    idea中web.xml报错 Servlet should have a mapping
  • 原文地址:https://www.cnblogs.com/ZERO-/p/7129105.html
Copyright © 2011-2022 走看看