题意:把N条电缆截成相同的M段,问截成的最大长度是多少?
思路:二分截的长度即可。(我不会告诉你我的程序样例都过不了)
http://acm.hdu.edu.cn/showproblem.php?pid=1551
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i ++)
#define rrep(i,a,b) for(int i = (b) ; i >= (a) ; i --)
#define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next)
#define cls(a,x) memset(a,x,sizeof(a))
#define eps 1e-8
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXE = 2e5+5;
typedef long long LL;
typedef unsigned long long ULL;
int T,n,m,k;
int fx[] = {0,1,-1,0,0};
int fy[] = {0,0,0,-1,1};
double A[10005] ;
double rights;
double sum;
void input() {
double tmp;
rights = 0;
rep(i,1,n) {
scanf("%lf",&A[i]);
rights += A[i];
}
}
int calc(double mid) {
int count = 0;
rep(i,1,n) {
count += (int)( A[i] / mid );
}
return count;
}
void solve() {
double left = 0;
double right = rights;
double mid ;
while(fabs(right-left)>eps) {
mid = (left + right) / 2;
if(calc(mid) < m) right = mid;
else left = mid;
}
printf("%.2lf\n",mid);
}
int main(void) {
while(scanf("%d %d",&n,&m),n+m) {
input();
solve();
}
return 0;
}