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. Lightoj 1006 Hex-a-bonacci

    Given a code (not optimized), and necessary inputs, you have to find the output of the code for the ...

  2. HDU1160 FatMouse's Speed —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...

  3. POI中HSSF和XSSF操作Excel

    POI中HSSF和XSSF操作Excel   在公司实习快一个月了,这段时间公司业务要用JAVA操作复杂的Excel报表.刚开始的Excel还好,没有涉及到复杂的图表,所以使用JXL操作Excel,但 ...

  4. lucene segment会包含所有的索引文件,如tim tip等,可以认为是mini的独立索引

    A Lucene index segment can be viewed as a "mini" index or a shard. Each segment is a colle ...

  5. bzoj 2006 超级钢琴 —— ST表

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2006 本来应该是可以用主席树,找区间最小值,取出来后再找那段区间的次小值...... 但也可 ...

  6. Apollo自动驾驶框架试玩

    2017年7月5日,百度举行了AI开发者大会,在会上发布了Apollo项目,并进行了演示,该项目在Github上已经能够被访问.出于一个程序员的好奇,昨天试玩了一把,确实不错. http://apol ...

  7. js调用的注意项

    注意将js代码写在调用的前面  这样他就知道了  自己所调用的函数是什么了

  8. Linux - 常用命令索引

    文件和目录操作 pwd - 显示当前所在的位置 cd - 切换目录 文件过滤及内容编辑 ... 文本处理三剑客 ... 系统信息查询与搜索文件 ... 文件备份与压缩 ... 用户管理与信息查询 .. ...

  9. Linux 常用命令十四 killall和pkill

    用killall杀死所有同名的进程. wang@wang:~/workpalce/git$ ps -aux | grep vim wang pts/ S+ : : vim a wang pts/ S+ ...

  10. How to Compare Means (均值比较)

    在比较数据的均值时,我们可能知道: 比较工厂当天生产的零件的长度是否合格 (length >= N mm),用 t-Test; 比较各一线城市的人均收入,用 ANOVA. 其实均值比较还有很多检 ...