当前位置: 代码迷 >> 综合 >> UVA 3635 Pie .
  详细解决方案

UVA 3635 Pie .

热度:87   发布时间:2023-09-23 05:45:08.0

题目地址:http://vjudge.net/problem/UVALive-3635

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);++i)
const double PI=acos(-1.0),EPS=1e-5;
const int maxn=10000+5;
int N,F;
double Area[maxn];
bool Check(double x){int sum=0;REP(i,1,N) {sum+=(int)(Area[i]/x);if(sum>=F+1) return true;}return false;
}
int main(int argc, char const *argv[])
{int T_T; scanf("%d",&T_T);while(T_T--){scanf("%d%d",&N,&F);double MaxA=0;REP(i,1,N){ int r;scanf("%d",&r); Area[i]=r*r*PI;MaxA=max(MaxA,Area[i]);}double L=0,R=MaxA;while(R-L>EPS){double mid=(R+L)/2;if(Check(mid)) L=mid;else R=mid;}printf("%.4lf\n", L);}return 0;
}