/***********
Author Smile
二分的另一种写法
以差值作为结束条件
注意eps的大小,最好是 1e-6 差不多够用了已经
二分的对象搞清楚,加一个判断条件,最后输出的是l
而且这个分段是 l = mid, r = mid 因为是double数据范围很小
注:这种 double 类型的题输入输出别用 cin cout 会超时
https://vjudge.csgrandeur.cn/contest/477149#problem/B
***********/
#include <iostream>
#include <cmath>
#define endl '\n'
using namespace std;
const double pi = 3.1415926;
const double eps = 1e-6;
const int N = 1e4 + 10;
int T, n, f;
double w[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--)
{
cin >> n >> f;
double maxx = 0;
for (int i = 1; i <= n; ++i)
{
cin >> w[i];
w[i] = w[i] * w[i] * pi;
if (w[i] > maxx)
maxx = w[i];
}
double l = 0, r = maxx, mid;
while (r - l >= eps)
{
mid = (l + r) / 2;
int ans = 0;
for (int i = 1; i <= n; ++i)
ans += w[i] / mid;
if (ans >= f + 1)
l = mid;
else
r = mid;
}
cout << l << endl;
}
return 0;
}
03-13
389
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)