https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/

传送带每天有最大传送量V,对于n个货物[w1,w2,w3...wn],要在D天内将所有货物传送完的V最小为多少?

二分每天最大传送量V,初始:Vhigh = sum(w),Vlow = max(w)。

class Solution
{
public:
int calc_days(vector<int>& weights, int V)
{
int len = weights.size(), days=, i=, cur=;
while(i<len)
{
if(cur+weights[i] > V)
{
days++;
cur=;
}
cur += weights[i++];
}
if(cur>)
days++;
return days;
} int shipWithinDays(vector<int>& weights, int D)
{
int high=, lenw=weights.size(), low=;
for(int i=; i<lenw; i++)
{
high += weights[i];
low = max(low, weights[i]);
}
int res=;
while(low<=high)
{
int mid = (high+low)>>;
if(D >= calc_days(weights, mid))
{
high = mid-;
res = mid;
}
else
low = mid+;
}
return res;
}
};

leetcode_1011. Capacity To Ship Packages Within D Days_binary search二分的更多相关文章

  1. Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days)

    Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days) 传送带上的包裹必须在 D 天内从一个港口运送到另 ...

  2. [Swift]LeetCode1011. 在 D 天内送达包裹的能力 | Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  3. Capacity To Ship Packages Within D Days LT1011

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  4. 128th LeetCode Weekly Contest Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  5. LeetCode 1011. Capacity To Ship Packages Within D Days

    原题链接在这里:https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ 题目: A conveyor belt h ...

  6. Leetcode: Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  7. Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  8. 【leetcode】1014. Capacity To Ship Packages Within D Days

    题目如下: A conveyor belt has packages that must be shipped from one port to another within D days. The  ...

  9. 【LeetCode】1014. Capacity To Ship Packages Within D Days 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. docker随谈

    最近在搞Docker,其实去年就听老师说过这个东西,说非常火,当时不以为然,还错把它当成docky.当时想想docky不就是一个快速启动工具么,有什么.现在想想真是惭愧... Docker的牛逼之处网 ...

  2. 谈一谈以太坊虚拟机EVM的缺陷与不足

    首先,EVM的设计初衷是什么?它为什么被设计成目前我们看的样子呢?根据以太坊官方提供的设计原理说明,EVM的设计目标主要针对以下方面: 简单性(Simplicity) 确定性(Determinism) ...

  3. 关于intent传递对象后是传递的对象的地址还是对象的拷贝?

    var intent = Intent(activity,SingleColorControlActivity::class.java); var bundle = Bundle()// bundle ...

  4. ACTION中获得数据的几种方式

    1.第一种是通过公司封装的方法. 2.第二种:是通过IF方法判断 3.第三种是通过:set/get获得

  5. django flask缓存memcache的key生成方法介绍

    去年的一个django项目中,使用了memcache作为系统缓存,并实现多台机器上的缓存共享.配置的cache如下图所示: 最近在项目调试过程中,发现memcache在进行缓存时,使用的key并不是实 ...

  6. 洛谷 P1072 Hankson 的趣味题 —— 质因数分解

    题目:https://www.luogu.org/problemnew/show/P1072 满足条件的数 x 一定是 a1 的倍数,b1 的因数,a0/a1 与 x/a1 互质,b1/b0 与 b1 ...

  7. Hibernate4 拦截器(Interceptor) 实现实体类增删改的日志记录

    转自:https://blog.csdn.net/he90227/article/details/44783099 开发应用程序的过程中,经常会对一些比较重要的数据修改都需要写日志.在实际工作的工程中 ...

  8. 任务42:EF Core Migration

    任务42:EF Core Migration 右边的是在VS2017中使用的命令,左边是在VSCode 的DOS窗体中使用的 最新版本的core 2.2.1的 版本创建以后已经没有model类了. 下 ...

  9. POJ2823:Sliding Window

    传送门 题意 有一个数列a,要求你求数列b和c,b[i]是a[i]-a[i+w-1]中的最小值,c[i]是最大值.如果a是1,3,-1,-3,5,3,6,7,则b为-1,-3,-3,-3,3,3,c为 ...

  10. bzoj 3456: 城市规划【NTT+多项式求逆】

    参考:http://blog.miskcoo.com/2015/05/bzoj-3456 首先推出递推式(上面的blog讲的挺清楚的),大概过程是正难则反,设g为n个点的简单(无重边无自环)无向图数目 ...