avatar
S*C
2
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
}
}
avatar
M*y
3
在国内买的
但是丢了一个 坏了一个
现在很痛苦啊。。
请问在美国哪里可以买到啊。。
多谢啦。
avatar
j*g
4
这破题都18% AC, 无法理解
avatar
c*w
5
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;
}
avatar
c*8
6
lintcode 跟 leetcode的区别是啥?这两个上面的题目差别很大么?要不要两个都刷下
avatar
d*n
7
这个简单,二分查找。[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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。