hihoCoder 1498 Diligent Robots

本文探讨了一个关于机器人工作调度的问题,即如何用最少的时间完成给定数量的任务。通过构建数学模型并利用程序实现,找到了最优解的方法。对于70%的数据规模,任务数限定在一百万之内;对于所有数据,任务数可达一万亿,构建时间在一小时内。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

时间限制: 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
思维题,不要想的太复杂。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
#define ll long long
int main()
{
    ll n,q,x,mi=0x3f3f3f3f;
    cin>>n>>q;
    x=sqrt(n);
    for(ll i=0;i<=x;i++)
    {
        ll w=(ll)pow(2,i);
        if(n%w==0)
            w=n/w+i*q;
        else
            w=n/w+1+i*q;
        mi=min(mi,w);
    }
    cout<<mi<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值