leetcode_1011. Capacity To Ship Packages Within D Days_binary search二分
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二分的更多相关文章
- Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days)
Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days) 传送带上的包裹必须在 D 天内从一个港口运送到另 ...
- [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 ...
- 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 ...
- 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 ...
- LeetCode 1011. Capacity To Ship Packages Within D Days
原题链接在这里:https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ 题目: A conveyor belt h ...
- 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 ...
- 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 ...
- 【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 ...
- 【LeetCode】1014. Capacity To Ship Packages Within D Days 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- Delphi全角转半角
function ToDBC( input :String):WideString;varc:WideString;i:Integer;beginc := input;for i:=1 to Leng ...
- create python project steps
Setting Up Your First Project You don't have to manually create the structure above, many tools will ...
- Linux内核--基于Netfilter的内核级包过滤防火墙实现
测试内核版本:Linux Kernel 2.6.35----Linux Kernel 3.2.1 原创作品,转载请标明http://blog.csdn.net/yming0221/article/de ...
- plink 与 ssh 远程登录问题
plink 是一种 putty-tools,ubuntu 环境下,如果没有安装 plink,可通过如下方法进行安装: $ echo y | sudo apt-get install plink 1. ...
- I.MX6 简单电路模拟USB设备的插入
/**************************************************************************** * I.MX6 简单电路模拟USB设备的插入 ...
- 动态点分治入门 ZJOI2007 捉迷藏
传送门 这道题好神奇啊……如果要是不带修改的话那就是普通的点分治了,每次维护子树中距离次大值和最大值去更新. 不过这题要修改,而且还改500000次,总不能每改一次都点分治一次吧. 所以我们来认识一个 ...
- 提高你的Python: 解释‘yield’和‘Generators(生成器)’
在开始课程之前,我要求学生们填写一份调查表,这个调查表反映了它们对Python中一些概念的理解情况.一些话题("if/else控制流" 或者 "定义和使用函数" ...
- VS2013在右键菜单添加命令插件开发
一.选择Visual Studio Package模板建立插件项目 由于此功能需要在右键菜单上添加命令,所以选择Visual Studio Package模板,根据模板向导步骤插件项目,在Select ...
- java日期和时间戳格式互转
// 将日期格式转换成时间戳 public static void main(String[] args) throws Exception{ String time = "2018-05- ...
- strcpy(转载)
转自:http://www.kuqin.com/clib/string/strcpy.html 原型:extern char *strcpy(char *dest,char *src); 用法:#in ...