2017-3-7-lint183-wood-cut

在河之洲
算法
lintcode

problem

lintcode183 wood cut

solution

注意两点

  1. 注意边界条件
  2. 取的是最大值而不是最小值.
    int woodCut(vector<int> L, int k) {
// write your code here
//先找到L里面最短的;
// write your code here
//先找到L里面最短的;
if (L.empty())
return 0;
int maxLen = 0;
for (int i = 0; i < L.size(); i++)
if (L[i] > maxLen)
maxLen = L[i];
//再进行切分;
int i = 1, j = maxLen;
while (i + 1 < j)
{
int m = i + (j - i) / 2;
int num = getCutNum(L, m);
if (num < k)
j = m;
else
i = m;
}
if (j != maxLen && i != 1)
return i;
if (j == maxLen)
if (getCutNum(L, j) >= k)
return j;
else
return i;
else if (getCutNum(L, 1) >= k)
return 1;
else
return 0; }
int getCutNum(vector<int> L, int len)
{
int num = 0;
for (int i = 0 ; i < L.size(); i++)
num += L[i] / len;
return num;
}

2017-3-7-lint183-wood-cut的更多相关文章

  1. 183.Wood Cut【hard】

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

  2. Lintcode: Wood Cut

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

  3. Wood Cut

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

  4. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  5. 二分难题 && deque

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

  6. Java Algorithm Problems

    Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...

  7. Win8Metro(C#)数字图像处理--2.17图像木刻效果

    原文:Win8Metro(C#)数字图像处理--2.17图像木刻效果  [函数名称] 图像木刻效果函数WoodCutProcess(WriteableBitmap src) [函数代码] ///& ...

  8. 二分查找总结及部分Lintcode题目分析 4

    二分法不只能像之前的记录,可以找到index~第二种类型是找到二分答案.有以下几个例子,都是之前二分法的扩展,不再赘述,只记录下忽略的点,以后回顾多注意~ 1. wood cut class Solu ...

  9. 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数

    先最大流跑一遍 在残存网络上把满流边容量+1 非满流边容量设为无穷大 在进行一次最大流即可 (这里的边都不包括建图时用于反悔的反向边) #include<cstdio> #include& ...

随机推荐

  1. 卡内操作系统COS

    https://wenku.baidu.com/view/dbaa94916bec0975f465e2e8.html 智能卡与cos技术简析: http://www.360doc.com/conten ...

  2. Linux 之 .bashrc 文件作用

    Linux 系统中很多 shell,包括bash,sh,zsh,dash 和 korn 等,不管哪种 shell 都会有一个 .bashrc 的隐藏文件,它就相当于 shell 的配置文件. 一般会有 ...

  3. Deep Learning - Install the Development Environment

    WLS(Windows Subsystem for Linux) Base WLS Installation Guide Initializing a newly installed distro W ...

  4. URL辅助方法

    URL辅助方法则负责用来产生url地址,那什么时候需要呢,以输出超链接来说,使用Html.ActionLink()辅助方法一定会产生超链接的a标签,如果只是想单纯的输出asp.net mvc的某个网址 ...

  5. CF961G Partitions(第二类斯特林数)

    传送门 对于每一个元素,我们只要能求出它的出现次数\(sum\),那么每个元素的贡献都是一样的,最终的答案为\(sum\times \sum_{i=1}^n w_i\) 那么分别讨论 如果这个元素自己 ...

  6. MCP|BFY|Proteome Analysis of Human Neutrophil Granulocytes From Patients With Monogenic Disease Using Data-independent Acquisition(单基因疾病患者中性粒细胞的DIA蛋白质组分析)

    文献名:Proteome Analysis of Human Neutrophil Granulocytes From Patients With Monogenic Disease Using Da ...

  7. MySql提示:The server quit without updating PID file(…)失败之解决办法(来源网络仅供参考)

    1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限 解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod ...

  8. LWIP应用指南学习。

    一 TCP接口函数:tcp_init() 必须在调用其它TCP函数之前调用,必须用一个硬件定时器来配置每TCP_FAST_INTERVAL (ms)调用一次tcp_fasttmr() :每TCP_SL ...

  9. 2017 ACM Arabella Collegiate Programming Contest div2的题,部分题目写个题解

    F. Monkeying Around   维护点在多少个线段上 http://codeforces.com/gym/101350/problem/F 题意:有m个笑话,每个笑话的区间是[L, R], ...

  10. Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心

    http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...