由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求解lintcode Wood Cut 问题
相关主题
lintcode delete digits怎么做?(CS) 求单词合成的那个题是咋作的来着?
求解lintcode Majority Number IIILongest Consecutive Sequence 问题释疑
lintcode subarray sum 怎么做?请教recursive backtracking问题的时间复杂度的分析
lintcode 上的 Count of Smaller Number before itself请问leetcode 上那道Longest Consecutive Sequence题
C++ 程序求助Find the longest word given a collection
find longest subarray with the equal number of 0's, 1'sliverampOA题目
这个怎么弄?面试题
LeetCode LongestValidParenthesesFacebook interview 面经
相关话题的讨论汇总
话题: wood话题: int话题: length话题: pieces话题: cut
进入JobHunting版参与讨论
1 (共1页)
S*******C
发帖数: 822
1
Wood Cut
18%
Accepted
Given n pieces of wood with length L[i] (integer array). Cut them into small
pieces to guarantee you could have equal or more than k pieces with the
same length. What is the longest length you can get from the n pieces of
wood? Given L & k, return the maximum length of the small pieces.
Note
You couldn't cut wood into float length.
Example
For L=[232, 124, 456], k=7, return 114.
Challenge
O(n log Len), where Len is the longest length of the wood.
http://lintcode.com/en/problem/wood-cut/
public class Solution {
/**
*@param L: Given n pieces of wood with length L[i]
*@param k: An integer
*return: The maximum length of the small pieces.
*/
public int woodCut(int[] L, int k) {
// write your code here
}
}
j********g
发帖数: 80
2
这破题都18% AC, 无法理解
c********w
发帖数: 2438
3
po个我的
public int woodCut(int[] L, int k) {
// write your code here
int n=L.length;
if(n==0)
return 0;
Arrays.sort(L);
int res=0;
int left=1, right=L[n-1];
while(left<=right){
int mid=(right-left)/2+left;
int count=0;
for(int i=n-1;i>=0;i--)
count+=(L[i]/mid);
if(count>=k){
res=mid;
left=mid+1;
}
else{
right=mid-1;
}
}
return res;
}
c****8
发帖数: 76
4
lintcode 跟 leetcode的区别是啥?这两个上面的题目差别很大么?要不要两个都刷下
d****n
发帖数: 397
5
这个简单,二分查找。[0, max(L)]区间开始,然后一直找下去,到区间长度为一。

small

【在 S*******C 的大作中提到】
: Wood Cut
: 18%
: Accepted
: Given n pieces of wood with length L[i] (integer array). Cut them into small
: pieces to guarantee you could have equal or more than k pieces with the
: same length. What is the longest length you can get from the n pieces of
: wood? Given L & k, return the maximum length of the small pieces.
: Note
: You couldn't cut wood into float length.
: Example

1 (共1页)
进入JobHunting版参与讨论
相关主题
Facebook interview 面经C++ 程序求助
Interview Question- Algorithmfind longest subarray with the equal number of 0's, 1's
问一道数据结构题这个怎么弄?
请教一道算法题LeetCode LongestValidParentheses
lintcode delete digits怎么做?(CS) 求单词合成的那个题是咋作的来着?
求解lintcode Majority Number IIILongest Consecutive Sequence 问题释疑
lintcode subarray sum 怎么做?请教recursive backtracking问题的时间复杂度的分析
lintcode 上的 Count of Smaller Number before itself请问leetcode 上那道Longest Consecutive Sequence题
相关话题的讨论汇总
话题: wood话题: int话题: length话题: pieces话题: cut