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 ...
随机推荐
- 百度面试经历_web前端开发
百度面试经历_web前端开发 --2016年09月24日校招杭州站 刚面试完,担心过去就忘记掉,故回来时在地铁上用手机码下面试题目,供参考,也留作自己以后的面试参考依据.
- HTTP要点概述:三,客户端和服务器,请求和响应
一,客户端和服务器: HTTP协议主要用于客户端和服务器之间的通信. 1,客户端(client):请求访问资源的一端.(知道为啥用C表示客户端了吧) 2,服务器(server):提供资源响应的一端. ...
- B2C
B2C是Business-to-Customer的缩写,而其中文简称为"商对客"."商对客"是电子商务的一种模式,也就是通常说的直接面向消费者销售产品和服务商业 ...
- bzoj2683(要改一点代码)&&bzoj1176: [Balkan2007]Mokia
仍然是一道cdq模版.. 那么对于一个询问,容斥一下分成四个,变成问(1,1)~(x,y),那么对于x,y,修改只有x'<=x&&y'<=y,才对询问有影响,那么加上读入顺 ...
- Mac下svn搭建和使用方法
先安装svn服务器,然后执行以下步骤: 1.创建svn服务器库:svnadmin create ~/Documents/tools/svn/server/code 2.启动svn服务器:svnserv ...
- 洛谷 P1311 选择客栈 —— 水题
题目:https://www.luogu.org/problemnew/show/P1311 看每个位置能否成为咖啡店,然后作为客栈和前面配对即可. 代码如下: #include<iostrea ...
- (转)IE内存泄露,iframe内存泄露造成的原因和解决方案
http://my.oschina.net/jsan/blog/11169 http://blog.csdn.net/tianma630/article/details/8502395 jQuery ...
- “Live Desktop” privacy statement
“Live Desktop” pays attention to your privacy protection. Sometimes we need some information to prov ...
- Rails5终端基本命令
更新: 2017/06/10 更新: 2017/06/21 增加迁移文件查看履历命令: rails db:migrate:status 迁移文件生成 ...
- 【爬坑系列】之docker的overlay网络配置(未完,待续)
理论知识储备: 想了解vxlan网络的知识:https://www.cnblogs.com/shuiguizi/p/10923841.html 想了解docker网络的原理知识:https://www ...