【二分法】poj 3122 分批萨

编程入门 行业动态 更新时间:2024-10-27 16:26:13

【二分法】<a href=https://www.elefans.com/category/jswz/34/1766382.html style=poj 3122 分批萨"/>

【二分法】poj 3122 分批萨

题目来源:poj 3122
参考:

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n, f;
const int maxn = 10010;
const double pi = acos(-1.0);
int a[maxn];
const double eps = 0.0001;bool judge(double weight)
{int cnt = 0;for (int i = 0; i < n; i++){cnt += (int)(a[i] / weight);}if (cnt < f){return false;}else{return true;}
}int main()
{int T;cin >> T;while (T--){cin >> n >> f;double low = 0;double high = 0;int temp = 0;for (int i = 0; i < n; i++){cin >> a[i];a[i] *= a[i];temp = max(a[i], temp);}high = temp;double mid = 0;sort(a, a + n);f++;while (high - low > eps){mid = (low + high) / 2;if (judge(mid)){low = mid;}else{high = mid;}}printf("%.4f\n", pi * mid);}return 0;
}

更多推荐

【二分法】poj 3122 分批萨

本文发布于:2024-02-11 04:46:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1679191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批萨   poj

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!