http://poj.org/problem?id=3122
题意
主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一个派上切下来的。
分析
二分答案,每次统计当前体积下能分配的人数。
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lc idx<<1
#define rc idx<<1|1
#define rson mid+1,r,rc
#define lson l,mid,lc
using namespace std;
typedef long long ll;
template <class T>
void test(T a) {
cout<<a<<endl;
}
template <class T,class T2>
void test(T a,T2 b) {
cout<<a<<" "<<b<<endl;
}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c) {
cout<<a<<" "<<b<<" "<<c<<endl;
}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = 1e9+;
int T;
void testcase() {
printf("Case %d: ",++T);
}
const int MAXN = 1e5+;
const int MAXM = ;
const double PI = acos(-1.0);
const double eps = 1e-;
double pie[MAXN];
int n,m;
int main() {
#ifdef LOCAL
freopen("data.in","r",stdin);
#endif // LOCAL
int T;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
double maxx = ;
for(int i=; i<n; i++) {
scanf("%lf",&pie[i]);
pie[i] *= pie[i];
if(maxx<pie[i]) {
maxx = pie[i];
}
}
m = m + ;
double l = ;
double r = maxx;
double mid;
while(r-l>eps) {
mid = (r+l)/;
int sum = ;
for(int i=; i<n; i++) {
if(pie[i]-mid>eps) {
sum += (int)pie[i]/mid;
}
}
if(sum>=m) l = mid;
else r = mid;
}
printf("%.4f\n",mid*PI);
}
return ;
}