算法:漆狗屋/书本分发(最大值最小问题)【查找】

漆狗屋/书本分发(最大值最小问题)

Description

Dilpreet wants to paint his dog- Buzo’s home that has n boards with different lengths[A1, A2,…, An]. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done under the constraints that any painter will only paint continuous sections of boards, say board {2, 3, 4} or only board {1} or nothing but not board {2, 4, 5}.
Constraints:1<=T<=100,1<=k<=30,1<=n<=50,1<=A[i]<=500

Input

The first line consists of a single integer T, the number of test cases. For each test case, the first line contains an integer k denoting the number of painters and integer n denoting the number of boards. Next line contains n- space separated integers denoting the size of boards.

Output

For each test case, the output is an integer displaying the minimum time for painting that house.

Sample Input 1

2
2 4
10 10 10 10
2 4
10 20 30 40

Sample Output 1

20
60

思路分析

参考
此类问题为:最大值最小问题,一般使用二分查找
工人可以视为桶,工作时间可以视为桶容量,即题目为在特定桶数量下,找到最大桶容量的最小值。

# 漆狗屋
# 分析:要以最快时间漆好狗屋,就要把最长时间减少到最短。
# 求最大值最小问题,一般用二分查找解决


def get_request_tub(cap, arr, p, b):    # 查找给定桶容量时所需的桶数量
    numTub = 1
    sum = 0
    for i in range(b):
        sum += arr[i]
        if sum > cap:
            numTub += 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值