题目:
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42065
#include <cstdio> #include <cmath> using namespace std; const double PI = acos(-1); double v[10005]; int N, F; bool test(double x) { int tot = 0; for(int i=0; i<N; i++) { tot += floor(v[i] / x); } return tot >= F; } int main () { int T, r; scanf("%d", &T); while(T--) { scanf("%d%d", &N, &F); ++F; double lb = 0, ub = -1; for(int i=0; i<N; i++) { scanf("%d", &r); v[i] = PI * r * r; if(v[i] > ub) ub = v[i]; } ub += 1; while(lb + 1e-5< ub) { // [, ) double mid = (lb + ub) / 2; if(test(mid)) lb = mid; else ub = mid; } printf("%.4lf\n", lb); } return 0; }
本文介绍了一道关于计算圆面积并进行分桶的算法题。通过输入多个圆的半径,使用二分查找的方法来确定每个桶的最大面积,以确保所有圆的面积总和达到指定数量。代码中实现了关键的数学计算和算法流程。
115

被折叠的 条评论
为什么被折叠?



