2017-3-7-lint183-wood-cut
2017-3-7-lint183-wood-cut
problem
solution
注意两点
- 注意边界条件
- 取的是最大值而不是最小值.
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的更多相关文章
- 183.Wood Cut【hard】
183.Wood Cut[hard] Given n pieces of wood with length L[i] (integer array). Cut them into small piec ...
- Lintcode: Wood Cut
Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you ...
- Wood Cut
Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- 二分难题 && deque
141. Sqrt(x) https://www.lintcode.com/problem/sqrtx/description?_from=ladder&&fromId=4 publi ...
- Java Algorithm Problems
Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...
- Win8Metro(C#)数字图像处理--2.17图像木刻效果
原文:Win8Metro(C#)数字图像处理--2.17图像木刻效果 [函数名称] 图像木刻效果函数WoodCutProcess(WriteableBitmap src) [函数代码] ///& ...
- 二分查找总结及部分Lintcode题目分析 4
二分法不只能像之前的记录,可以找到index~第二种类型是找到二分答案.有以下几个例子,都是之前二分法的扩展,不再赘述,只记录下忽略的点,以后回顾多注意~ 1. wood cut class Solu ...
- 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数
先最大流跑一遍 在残存网络上把满流边容量+1 非满流边容量设为无穷大 在进行一次最大流即可 (这里的边都不包括建图时用于反悔的反向边) #include<cstdio> #include& ...
随机推荐
- zkw线段树专题
题目来自大神博客的线段树专题 http://www.notonlysuccess.com/index.php/segment-tree-complete/ hdu1166 敌兵布阵题意:O(-1)思路 ...
- linux下的函数dirname()和basename()使用
总览 #include <libgen.h> char *dirname(char *path); char *basename(char *path); 说明 函数以 '/' 为分隔符 ...
- Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析
Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析 一.加载数据 import pandas as pd import numpy as np url = ('http ...
- SharePoint 2010 搜索结果没有显示部分文件
Why SharePoint 2010 search does not show some results? SharePoint 2010 search is better than ever ...
- HDU - 1869 六度分离 Floyd多源最短路
六度分离 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即 ...
- python读写xlsx
1使用openpyxl库读写excel xlrd和xlwt处理的是xls文件,单个sheet最大行数是65535,如果有更大需要的,建议使用openpyxl函数,最大行数达到1048576. 如果数 ...
- AndroidStudio常用快捷键
Alt+Insert:查找override函数 Alt+Enter:自动引包
- 洛谷P3405 [USACO16DEC]Cities and States省市
P3405 [USACO16DEC]Cities and States省市 题目描述 To keep his cows intellectually stimulated, Farmer John h ...
- 洛谷P1447 [NOI2010]能量采集(容斥)
传送门 很明显题目要求的东西可以写成$\sum_{i=1}^{n}\sum_{j=1}^m gcd(i,j)*2-1$(一点都不明显) 如果直接枚举肯定爆炸 那么我们设$f[i]$表示存在公因数$i$ ...
- 利用正则取出Stirng中“”引号内的内容
// 取出所有""中间的内容,正则如下 Pattern pattern1 = Pattern.compile("(?<=\")([\\S]+?)(?=\& ...