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. SelectObject()函数详解

    SelectObject 把一个对象(位图.画笔.画刷等)选入指定的设备描述表.新的对象代替同一类型的老对象. HGDIOBJ SelectObject(   HDC hdc,          // ...

  2. HDU - 5451 Best Solver(循环节+矩阵快速幂)

    Best Solver The so-called best problem solver can easily solve this problem, with his/her childhood ...

  3. hdu 3037 费马小定理+逆元除法取模+Lucas定理

    组合数学推推推最后,推得要求C(n+m,m)%p 其中n,m小于10^9,p小于1^5 用Lucas定理求(Lucas定理求nm较大时的组合数) 因为p数据较小可以直接阶乘打表求逆元 求逆元时,由费马 ...

  4. EasyUI获取所有选中行中的某一列的值

    var PointIds=[]; for (var i = 0; i < wPoint_rows.length; i++) { //PointIds.push(wPoint_rows[i][&q ...

  5. 30个物联网传感器小实验:三行代码点亮LED灯

    30个物联网传感器小实验:三行代码点亮LED灯 三行代码点亮LED灯 LED灯闪烁 LED灯调亮度 LED淡入淡出 不写一行代码点亮LED灯 全彩RGB灯 面包板 30个物联网传感器小实验:三行代码点 ...

  6. 计蒜课/ 微软大楼设计方案/中等(xjb)

    题目链接:https://nanti.jisuanke.com/t/15772 题意:中文题诶- 思路:对于坐标为p1(x1, y1), p2(x2, y2) 的两个核心, 其中 x1 <= x ...

  7. js的Element.scrollIntoView的学习

    1.Element.scrollIntoView()    该方法让当前元素滚动到浏览器窗口的可是区域内: 2.语法: element.scrollIntoView();//等同于element.sc ...

  8. Python学习笔记(字典)

    今天学习一个python中的基本类型--字典(dictionary) 字典这种数据结构有点像我们平常用的通讯录,有一个名字和这个名字对应的信息.在字典中,名字叫做“键”,对应的内容信息叫做“值”.字典 ...

  9. C# Monitor与线程同步

    Monitor对象(C#知识点总结系列:4.C#中Monitor和Lock以及区别) 1.Monitor.Enter(object)方法是获取锁,Monitor.Exit(object)方法是释放锁, ...

  10. Ionic中基于js的扩展(指令和服务)来实现各种效果

    1.ion-header-bar ion-footer-bar ion-content align-title='left/ritght/center <body> <ion-hea ...