Pie UVA - 12097
题意:
有f+1个人要分N种圆形pai,每个人分到一整块pai(而不是几块拼在一起,且面积要相同,不必是圆形)。
求:
每个人分到的pai应尽量大。
思路:
- 典型的二分答案。
- 这里注意二分时的L和R是
浮点数
。
反思:(如下)
const double eps = 1e-5;
//
while(R-L>eps){///L<R
double mid=(R+L)/2;
if(check(mid)) L = mid;
else R = mid;
}
AC
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
const double eps = 1e-5;
const double PI = acos(-1.0);
const int maxn = 1e4+10;
double A[maxn];
int f, n;
bool check(double area){
int res = 0;
For(i,1,n)res += floor(A[i]/area);
return res>=f+1;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cout<<PI<<endl;
int tt; scanf("%d", &tt);
while(tt--){
scanf("%d%d", &n, &f);
double L = 0, R = 0;
For(i,1,n){
int r; scanf("%d", &r);
A[i] = r*r*PI;
R = max(R, A[i]);
}
while(R-L>eps){///L<R
double mid=(R+L)/2;
if(check(mid)) L = mid;
else R = mid;
}
printf("%.4f\n", L);
}
return 0;
}