题目大意:n段电缆,要分为m段,问如何才能分成并且每段等长&&长度>=1
思路:二分最大长度,注意有精度问题可以变成整形的。
#include<map>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<stack>
#include<cstring>
#include<algorithm>
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-5
const double PI=acos(-1.0);
using namespace std;
int arr[100010];
int main(){
int n,m;
double t;
int l,r,mid;
while(~scanf("%d%d",&n,&m)){
l=r=0;
for(int i = 0;i < n;++ i){
scanf("%lf",&t);
arr[i]=t*100;
r = max(r,arr[i]);
}
l = 1;
while(r >= l){
int nu=0;
mid = (r + l) / 2;
for(int i = 0;i < n;++ i){
nu += (arr[i]/mid);
}
if(nu < m)
r = mid-1;
else
l = mid+1;
}
printf("%.2f\n",(double) (r*1.0/100.0) );
}
return 0;
}