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
}
}
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
}
}
M*y
3 楼
在国内买的
但是丢了一个 坏了一个
现在很痛苦啊。。
请问在美国哪里可以买到啊。。
多谢啦。
但是丢了一个 坏了一个
现在很痛苦啊。。
请问在美国哪里可以买到啊。。
多谢啦。
j*g
4 楼
这破题都18% AC, 无法理解
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;
}
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
6 楼
lintcode 跟 leetcode的区别是啥?这两个上面的题目差别很大么?要不要两个都刷下
?
?
d*n
7 楼
这个简单,二分查找。[0, max(L)]区间开始,然后一直找下去,到区间长度为一。
small
【在 S*******C 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 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
small
【在 S*******C 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 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
相关阅读
昨天嫁了,钻戒换成了美容预算,请大家出主意帮忙看看这衣服退不买wedding band ring去哪买呢?不知道多少男人痛恨自己没有先见之明! (转载)化妆水面膜敷几分钟2011各公司年会争相拼美女 度娘、易娘走红网络 (转载)[转载] 虽说国内空气不好污染严重,但是为毛很多菜和肉还是要比美国的鲜美,人的气色也都很不错-参加活动-- 画龙点睛之各种零零碎碎笑死了...这姑娘真不容易啊!美女们都来按教程学习学习哦 (转载)鸭子包包3选一bergdrof goodman买1000送300,到本周日结束!!Jan16,2012参加活动 画龙点睛 ——基本色的衣服+彩色的配饰参加[活动]画龙点睛分享一点玉兰油洗脸刷贡献一个coach online 25% code请教香水的问题,谢谢[参加活动]恭喜小龙女新班上任有人在dinodirect买过衣服吗这个FACIAL SAUNA 怎么样[转载] 紫砂内胆的慢炖锅