hdu 1551 Cable master 二分

 

/*
* hdu1511.c
*
* Created on: 2011-10-9
* Author: bjfuwangzhu
*/

#include<stdio.h>
#include<math.h>
#define eps 1.0e-8
#define nmax 10001
double num[nmax];
int cmp(int n, double aver) {
int i, temp;
for (i = 0, temp = 0; i < n; i++) {
temp += (int) (num[i] / aver);
}
return temp;
}
void solve(int n, int k, double sum) {
double left, right, mid;
left = 0, right = sum / k, mid = 0.0;
while (fabs(left - right) > eps) {
mid = (left + right) / 2;
if (cmp(n, mid) >= k) {
left = mid;
} else {
right = mid;
}
}
printf("%.2lf\n", mid);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int n, k, i;
double sum;
while (~scanf("%d %d", &n, &k) && (n || k)) {
for (i = 0, sum = 0; i < n; i++) {
scanf("%lf", num + i);
sum += num[i];
}
solve(n, k, sum);

}
return 0;
}

你可能感兴趣的:(master)