题目链接:http://poj.org/problem?id=1064
题意:有n条绳子,他们的长度是Li,如果从他们中切割出K条长度相同的绳子,这相同的绳子每条有多长,输出至小数点后两位
“ then the output file must contain the single number "0.00" (without quotes).”不是四舍五入到两位,一般四舍五入题目会说“bounded to”的提示
显然想得到的绳子越短就越能得到,绳子太长就得不到,二分搜即可
//236K 94MS
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int n,k;
double a[10100];
bool judge(double x)
{
int cnt=0;
for(int i=1;i<=n;i++){
cnt+=a[i]/x;
}
return cnt>=k? 1:0;
}
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
double lb=0,ub=100100;
while(ub-lb>1e-5){
double mid=(lb+ub)/2;
if(judge(mid)){
lb=mid;
}
else{
ub=mid;
}
}
printf("%.2f\n",floor(ub*100)/100);
return 0;
}