AcWing 680. 剪绳子
原题链接
简单
作者:
回归线
,
2021-03-28 08:33:01
,
所有人可见
,
阅读 337
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 100010;
int n, m;
int a[N];
bool check(double x) {
int res = 0;
for (int i = 0; i < n; ++i) {
res += floor(a[i] / x);
if (res >= m) {
return true;
}
}
return false;
}
int main() {
scanf("%d%d",&n, &m);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
double l = 0;
double r = 1e9;
while (l + 1e-4 < r) {
const double mid = (l + r)/2.0;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
printf("%.2f", r);
return 0;
}