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. Linear Algebra - Determinant(几何意义)

    二阶行列式的几何意义 二阶行列式 \(D = \begin{vmatrix}a_1&a_2\\b_1&b_2\end{vmatrix} = a_1b_2 - a_2b_1\) 的几何意 ...

  2. ]Linq to EF 增删改查

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  3. ASP.NET Core MVC 视图

    ASP.NET Core MVC中视图的知识和ASP.NET MVC有很多相似之处,学习难度较低.以下内容主要体现了编程中模块化的思想,模块化才应是我们关注的重点. Layout 布局用于提供各个页面 ...

  4. wampserver2.5局域网公网IP访问配置

    wampserver2.5集成环境的安装和使用就不多说了,网上有很多教材.安装好后找到apache的配置文件httpd.conf.默认位置是: swap安装目录\wamp\bin\apache\apa ...

  5. 使用Git版本控制工具管理GitHub

      使用Git版本控制工具管理GitHu Git是一个分步式的管理系统:只要上传操作得当,所有的都可以相当于是中央服务器,成员代码共享,A写的代码B也有,一般把一个人当做主机,其他人通过该主机拼装代码 ...

  6. day9函数作业详解

    1.day9题目 1,整理函数相关知识点,写博客. 2,写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者. 3,写函数,判断用户传入的对象(字符串.列表.元组 ...

  7. Codeforces 27D(二分染色)

    要点 将边作为染色,如果交叉则异色 #include <cstdio> #include <algorithm> #include <functional> usi ...

  8. Uva12210-A Match Making Problem

    对于每个数字二分找到大于等于它的数,再暴力找到第一个小于它的数 #include<bits/stdc++.h> #define inf 0x3f3f3f3f ; using namespa ...

  9. Python入门_汇总_未完待续

    if/elseif/else for while break continue 多重循环 list [] duple() dict {} set {[]} 函数 help(abs) 查看abs函数的帮 ...

  10. shell 获得调用的python脚本的print值和错误log

    1. shell 获得调用的python脚本的print值 python test.py > out.log 2.shell 获得调用的python脚本的错误log python test.py ...