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
相关阅读
很喜欢这个帽子,不知道美国哪能买的到SAKS 啥时候FF 活动啊? 牌子比BLOOMIE好很多Estee Lauder: Choose 4 Deluxe Samples With Any Purchase. PFBB at Louis Vuitton PartyJoin Shiseido in the Fight Against Breast Cancer强烈建议IIcutie 奔一下全身不遮脸的正面照哪里有卖夹着耳朵的耳环?这件好看吗?想听听大家建议 要不要留这件风衣怎么样?说说头发吧。赞Redken All Soft白女也很讨厌亚女过界抢男人 (转载)Looking for new pics of the girl...奔我的闺密们:) (转载)请问清理肠胃 便秘用什么好?调查---女性最怕哪种变老?苏打粉哪里有卖?梦魇么 (转载)关于ugg,可以买那些非正牌的么兔子牙和眼袋问题(图)