#include <cstdio>
#define MAXN 100
using namespace std;
int Incise_Num(int a[],int n,int len);
int main()
{
int n,w[MAXN];
scanf("%d",&n); //n根木棒
int left = 0,right = 0; //木棒长度的上下界均初始化为0
for(int i = 0; i < n; i++){
scanf("%d",&w[i]);
if(right < w[i]){ //更新上界
right = w[i];
}
}
int k; //至少k段长度相等的木棒
scanf("%d",&k);
while(left < right){ //第一个满足条件"长度为len时能得到的木棒段数<k"的len
int mid = (left + right) / 2;
if(Incise_Num(w,n,mid) < k){
right = mid;
}
else{
left = mid + 1;
}
}
printf("%d",left - 1);
return 0;
}
//当前长度为len时能切割的段数
int Incise_Num(int a[],int n,int len)
{
int coun = 0;
for(int i = 0; i < n; i++){
coun += a[i] / len;
}
return coun;
}
木棒切割问题-二分法
最新推荐文章于 2024-01-03 08:57:47 发布