| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 11776 | Accepted: 4076 | Special Judge | ||
Description
My birthday is coming up and traditionally I‘m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are
coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though. Input
Output
Sample Input
3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2
Sample Output
25.1327 3.1416 50.2655
题意好麻烦:有n个pi,f个朋友,还有一个自己,给出每个pi的大小,每个pi可以切成几个蛋糕,而且所有pi切出的蛋糕都必须一样大,每个人至少分一个蛋糕,求最大的蛋糕的体积。高均为1.
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define maxn 25100000
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
int a[maxn];
int n,f;
bool ok(double x){
int ans=0;
for(int i=0;i<n;i++){
ans+=a[i]*a[i]*pi/x;
}
if(ans<f+1)return true;
else return false;
}
int main()
{
int t;
freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&f);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
double ua=0.0;
double ub=1000000000;
double mid;
/*
while(ub-ua>eps){ //两种方法均可,此题对精度要求比较低
mid=(ua+ub)/2;
if(ok(mid))ub=mid;
else ua=mid;
}*/
for(int i=0;i<100;i++){
mid=(ua+ub)/2;
if(ok(mid))ub=mid;
else ua=mid;
}
printf("%.4f\n",mid);
}
}
原文:http://blog.csdn.net/u013497977/article/details/44904423