zoukankan      html  css  js  c++  java
  • hihocoder-1498-Diligent Robots

    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

    题解:

      使用贪心算法的思想。

      样本复制之后需要去生产才有效,所以机器人必定是先复制完。

      还有一个想法是是否需要一边复制一边生产,这个想法是否定的,假如n生产m复制,得到的是 m + (q+1)*n.  如果是一起复制,则得到的是 (m + n)*q , 大于前者。

    #include <cstdio> 
    #include <cstdlib> 
    
    int main()
    {
        int q; 
        long long cnt, n, k; 
        while(scanf("%lld %d", &n, &q) != EOF)
        {
            cnt = 0; 
            k = 1; 
            while(2*q*k < n)
            {
                k *= 2; 
                cnt += q; 
            }
            cnt += n / k; 
            if(n%k != 0)
            {
                cnt += 1; 
            }
            printf("%lld
    ", cnt );
        }
        return 0; 
    }
    

      

  • 相关阅读:
    linux查看系统类型和版本
    javascript 中的继承实现, call,apply,prototype,构造函数
    redis原理分析
    HashTable 简述
    算法之 快速排序
    react js 之生命周期
    Java源代码编译过程
    Java字节码文件结构---概述
    Java程序运行时内存划分
    数据结构--汉诺塔--借助栈实现非递归---Java
  • 原文地址:https://www.cnblogs.com/zhang-yd/p/11025375.html
Copyright © 2011-2022 走看看