题目链接:http://poj.org/problem?id=1064
题意:给你n条绳子,长度分别为Li,从中割出K条长度相同的,使其长度最大化。
思路:直接二分搜索答案。。
代码:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;
#define clr(x, y) memset(x, y, sizeof(x))
#define fr(i,n) for(int i = 0; i < n; i++)
#define fr1(i,n) for(int i = 1; i <= n; i++)
#define upfr(i,j,n) for(int i = j; i <= n; i++)
#define dowfr(i,j,n) for(int i = n; i >= j; i--)
#define scf(n) scanf("%d", &n)
#define scf2(n,m) scanf("%d %d",&n,&m)
#define scf3(n,m,p) scanf("%d %d %d",&n,&m,&p)
#define ptf(n) printf("%d",n)
#define ptf64(n) printf("%I64d",n)
#define ptfs(s) printf("%s",s)
#define ptln() printf("\n")
#define ptk() printf(" ")
#define ptc(c) printf("%c",c)
#define srt(a,n) sort(a,n)
#define LL __int64
#define pi acos(-1.0)
#define eps 0.00001
#define maxn 10010
#define mod 1000000007
#define inf 100005
double a[maxn];
int n,k;
bool C(double x)
{
int sum = 0;
fr(i, n)
sum += (int)(a[i] / x);
return sum >= k;
},
int main()
{
// freopen("in.txt","r",stdin);
while(scf2(n, k) == 2)
{
fr(i, n)
scanf("%lf", &a[i]);
double lb = 0, ub = (double)inf;
while(ub - lb > eps)
{
double m = (lb + ub) / 2;
if(C(m))
lb = m;
else
ub = m;
}
printf("%.2lf\n", floor(ub*100)/100);
}
return 0;
}