- 剪绳子 (二分)
https://www.acwing.com/activity/content/problem/content/3418/1/
胡写
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
double a[N];
int n, m;
bool check(double len){
int cnt=0;
for(int i=0;i<n;i++){
int c=a[i]/len;
cnt+=c;
}
return cnt<m;
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)cin >> a[i];
double l = 0, r = 1e9;
while (fabs(r - l) > 0.001) {
double m = (l + r) / 2;
if(check(m))r=m;
else l=m;
}
printf("%.2f", l);
return 0;
}
网友评论