HU-969 Pie

2884 ワード

http://acm.hdu.edu.cn/showproblem.php?pid=1969
                       Pie
Time Limit:5000/1000 MS(Java/Others)    メモリLimit:65536/32768 K(Java/Others)Total Submission(s):3303    Acceepted Submission(s):1280
Problem Description
My bithday is comping up and tradionally 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.com.comping to my party and each the piecone.Thagenot several small pieces since that look s messy.This piece can be one whole pie though.
Myfrienininds ararar very annoying and if one of them gets a biggnegggaaaaaathe othes、they start coplining.Threfore all of them shougget equallysizd(but not necesisisisisisizze equalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalallyshshped)piped)pispspeceeeeeeeeeeeeeeeeeeeeeeeeeeeee for myself too、and that piece shound also be of the same size.
What is the larget possible piece size all of us can get?All the pies are cylindrical in shop and they all have the same height 1,but the radii of the pies can be different.
 
Input
One line with a positive integer:the number of test cases.The n for each test case:---One line with two integers N and F with 1<=N,F<=10 000:the number of pies and the number of frinds.One the the the number.One the the the the the the number。
 
Output
For each test case,output one line with the larget st possible V such that me and my friends can all get a pie of size V.The answer shound given as front point number with aber sour most
 
Sample Input
3
3
4 3
1 24
5
10 5
1 4 2 3 4 5 5 5 5 4 2
 
Sample Output
25.1327
3.1416
50.2655
#include<stdio.h>
#include<math.h>
#define pi  acos(-1.0)
int n,f;
double a[10005];
int cmp(double v)
{
	int i,sum=0;
	for(i=0;i<n;i++)
      sum+=int(a[i]/v);
	if(sum>=f)
		return 1;
	else
		return 0;
}
int main()
{
  int t,i;
  double size,right,left,mid,sum,temp;;
  scanf("%d",&t);
  while(t--)
  {
	    sum=0;
	  scanf("%d%d",&n,&f);
	   f++;
	  for(i=0;i<n;i++)
	  {
		  scanf("%lf",&temp);
          a[i]=pi*temp*temp;
		  sum+=a[i];
	  }
	  size=sum/f;
      left=0;right=size;
	  while(right-left>1e-6)
	  {
		  mid=(right+left)/2;
		  if(cmp(mid))
			  left=mid;
		  else
			  right=mid;
	  }
	  printf("%.4lf
",mid); } return 0; }