http://www.lintcode.com/en/problem/wood-cut/#

二分答案,贪心验证,具有单调性

class Solution {
public:
/**
*@param L: Given n pieces of wood with length L[i]
*@param k: An integer
*return: The maximum length of the small pieces.
*/
int woodCut(vector<int> L, int k){
if(L.empty()) return 0;
LL low=0, high=*max_element(L.begin(), L.end());
while(low<high){
if(low+1==high){
LL ans=0;
for(auto e: L){
ans+=e/high;
}
if(ans>=k) return high;
else return low;
}
LL mid=(low+high)/2;
LL ans=0;
for(auto e: L){
ans+=e/mid;
}
if(ans>=k) low=mid;
else high=mid-1;
}
return low;
}
}S;

introsort C++ STL 没有最坏情况

timsort msort isort 综合

dual pivot qsort JDK7 arrays.sort 里面採用 任然有最坏n^2情况

woodcut的更多相关文章

  1. 【刷题笔记】--lintcode木头加工(java)

    木头加工 题目描述 有一些原木,现在想把这些木头切割成一些长度相同的小段木头,需要得到的小段的数目至少为 k.当然,我们希望得到的小段越长越好,你需要计算能够得到的小段木头的最大长度. 注意事项 木头 ...

  2. Lintcode: Wood Cut

    Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you ...

  3. 九章lintcode作业题

    1 - 从strStr谈面试技巧与代码风格 必做题: 13.字符串查找 要求:如题 思路:(自写AC)双重循环,内循环读完则成功 还可以用Rabin,KMP算法等 public int strStr( ...

  4. Wood Cut

    Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you ...

  5. 二分难题 && deque

    141. Sqrt(x) https://www.lintcode.com/problem/sqrtx/description?_from=ladder&&fromId=4 publi ...

  6. 木材加工(LintCode)

    木材加工 有一些原木,现在想把这些木头切割成一些长度相同的小段木头,需要得到的小段的数目至少为 k.当然,我们希望得到的小段越长越好,你需要计算能够得到的小段木头的最大长度. 样例 有3根木头[232 ...

  7. 183.Wood Cut【hard】

    183.Wood Cut[hard] Given n pieces of wood with length L[i] (integer array). Cut them into small piec ...

  8. 二分法 Binary Search

    二分法还是比较常见和简单的,之前也遇到过一些二分的相关题目,虽然不难,但是每次都需要在边界问题上诸多考虑,今天听了九章算法的课程,学习到一种方法使得边界问题简单化. 二分法的几个注意点: 1. mid ...

  9. 2017-3-7-lint183-wood-cut

    2017-3-7-lint183-wood-cut 在河之洲 算法 lintcode problem lintcode183 wood cut solution 注意两点 注意边界条件 取的是最大值而 ...

随机推荐

  1. Day01:我的Python学习之路

    1.Python是什么语言? Python是动态的解释性的强类型定义的语言. (1)动态语言与静态语言 ①静态语言:在编译期间就会去做数据类型检查的语言,如C,C++. ②动态语言:在运行期间才会去做 ...

  2. 详解Spring面向切面编程(AOP)三种实现

    一.什么是AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善. ...

  3. js中表格的相关操作

    tHead:表头 tBodies:表格正文 tFoot:表格尾 rows:行 cells:列 表格的应用: 1.获取 2.表格创建 3.隔行变色 4.删除一行 <!DOCTYPE html> ...

  4. docker:安装tomcat

    文章来源:http://www.cnblogs.com/hello-tl/p/8929879.html 0.下载镜像 # docker pull tomcat:8.5 1.复制tomcat配置 先启动 ...

  5. scrollLeft属性设置无效的一个记录

    首先应该明确scrollLeft这个属性,只有当div中的内容长度大于当前div的长度是才能working,根据这个我我找到了一个很神奇的地方,而且我注意到这个${}连注释里面都能替换过来! 以下是正 ...

  6. 【07】QQ群管理公告小结:

    [07]QQ群管理公告小结:   01,请看公告遵守相关规定. 02,群内除QQ自带的缺省表情外(不是QQ的VIP或大图表情),禁止发送大表情,大图片(展示问题的屏幕截图除外),   03,修改群名片 ...

  7. POJ-2387Til the Cows Come Home,最短路坑题,dijkstra+队列优化

    Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K       http://poj.org/problem?id=238 ...

  8. HDU-1232/NYOJ-608畅通工程,并查集模板题,,水过~~~

    畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) http://acm. ...

  9. 亲历dataguard的一些经验问答题

    问题1:是否log_archive_dest_n=service中进程使用lgwr时(如log_archive_dest_2='service=DBSTD LGWR SYNC'),备库就一定要建立st ...

  10. SpringBoot Beans管理和自动配置

    原 SpringBoot Beans管理和自动配置 火推 02 2017年12月20日 21:37:01 阅读数:220 SpringBoot Beans管理和自动配置 @SpringBootAppl ...