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 ...
随机推荐
- bzoj2101【Usaco2010 Dec】Treasure Chest 藏宝箱
2101: [Usaco2010 Dec]Treasure Chest 藏宝箱 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 418 Solved: ...
- casperjs在拆分文件后的中文乱码问题的解决
windows环境. capserjs的中文乱码使用phantom.outputEncoding="GBK";即可解决. 但当我们脚本很大,需要拆分时(参考http://docs. ...
- openssl动态库编译
通常Linux系统自带OpenSSL,但是其so文件由于没有debug信息,因此无法跟踪内部函数,对于学习 不太方便,需要通过源码重新安装. 我的Linux系统是CentOS7,自带的 ...
- POJ - 2516 Minimum Cost(最小费用最大流)
1.K种物品,M个供应商,N个收购商.每种物品从一个供应商运送到一个收购商有一个单位运费.每个收购商都需要K种物品中的若干.求满足所有收购商需求的前提下的最小运费. 2.K种物品拆开来,分别对每种物品 ...
- echo 到 stderr
This question is old, but you could do this, which facilitates reading: >&2 echo "error& ...
- java抛出异常后,后续代码是否可继续执行
参考:https://www.cnblogs.com/wangyingli/p/5912269.html 仅此可正常执行异常后内容 try{ throw new Exception("参数越 ...
- Resolve the error: an error occurred during local report processing
Issue: an error occurred during local report processing.the definition of the report'Main Report'is ...
- Goland软件使用教程(二)
Goland软件使用教程(二)一.编码辅助功能 1. 智能补全 IDE通过自动补全语句来帮助您来编写代码.快捷键“Ctrl+shift+空格”将会给你一个在当前上下文中最相关符号的列表,当您 ...
- maven仓库错误
1.jai_core 时间:2018年3月21日10:04:57 URL:https://mvnrepository.com/artifact/javax.media/jai_core/1.1.3 / ...
- Linux 常用命令八 find
一.find命令 find命令用于查找文件. 按文件名字查找: wang@wang:~/workpalce/python$ sudo find / -name "create.txt&quo ...