截取
【题目描述】
给你N段线的长度,现在要你从他们上面切下K段来(切下的不能合并),使得这K段长度相等,并且最大。如若求出的答案小于0.01,则认为无解,输出0.00。(所有非整数都精确到了两位,输出亦然)1<=N,K<=10000
【样例输入】
4 11
8.02(在1到100000之间的实数)
7.43
4.57
5.39
【输出样例】
2.00
程序:
var
n,k,i:longint;
w:real;
sum,max,s,best:int64;
a:array[0..20000]of longint;
function check(x:int64):int64;
var
i:longint;
e:int64;
begin
e:=0;
for i:=1 to n do
e:=e+a[i] div x;
check:=e;
end;
function find(l,r:int64):int64;
var
mid,ans:int64;
begin
if l>r then exit;
mid:=(l+r) div 2;
ans:=check(mid);
if ans<k then find(l,mid-1) else
begin
if (ans<s)or((ans=s)and(best<mid)) then
begin
s:=ans;
best:=mid;
end;
find(mid+1,r);
end;
end;
begin
readln(n,k);
sum:=0;
for i:=1 to n do
begin
readln(w);
a[i]:=round(w*100);
sum:=sum+a[i];
end;
max:=sum div k;
s:=maxlongint;
find(1,max);
if s=maxlongint then write('0.00') else write(best/100:0:2);
end.