对网线的数目二分答案,个数数找小了就网线变小,找大了就变大1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#include<iostream>
#include<cstdio>
using namespace std;
int n,k,a[19999];int l=1,r=0;
int check(int x){
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=a[i]/x;
}
return ans;
}
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
double x;
scanf("%lf",&x);
a[i]=x*100;
r=max(r,a[i]);
}
if(check(r)==k)
{printf("%.2lf",r/100.0);
return 0;
}
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid)>=k) l=mid+1;
else r=mid-1;
}
printf("%.2lf",(r)/100.0);
}