C-sub-pie

Source: Internet
Author: User

My birthday is coming up and traditionally I ' m serving pie. Not just one pie, no, I had a number N of them, of various tastes and of various sizes. F of my friends is coming to my party and each of the them gets a piece of pie. This should is one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.

My Friends is very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (and not necessarily equally shaped) pieces, even if this leads to some pie Getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also is of the same size. What's the largest possible piece size all of us can get? All the Pies is cylindrical in shape and they all has the same height 1, but the radii of the Pies can is different.

Input one line with a positive integer:the number of test cases. Then to each test case:

one line with a integers N and F with 1≤n, f≤10000:the number of pies and the number of friends.

one line with N integers ri with 1≤ri≤10000:the radii of the Pies.

Output for each test case, output one line with the largest possible volume V such then me and my friends can all get a pi e Piece of Size v.

The answer should is given as a oating point number with an absolute error of in most 10−3.

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

Problem-solving ideas: This is a matter of pie, there are n pieces of different flavors of the cake, to f a friend and himself, each friend gets the cake must be the same size, and taste can only have one, but the shape can be different, ask each friend to get the largest pie area, this topic has a high-precision problem needs attention, is pi, To define it as ACOs (-1.0) so that there is no error, the dichotomy can be used to gradually achieve

Program code:

#include <cstdio>#include<cmath>#include<algorithm>using namespacestd;DoublePi=acos (-1.0);Doublep[10000+Ten];DoubleSUM,MAXN;inti,n,f,t,k,cnt;Doublel,r,m;intMain () {scanf ("%d",&t);  while(t--) {scanf ("%d%d",&n,&f); F++; L=sum=0;  for(i=0; i<n;i++) {scanf ("%d",&k); P[i]=pi*k*K; L=Max (p[i],l); Sum+=P[i]; } l=l/F; R=sum/F;  while(L +0.00001<r) {m= (l+r)/2; CNT=0;  for(i=0; i<n;i++) CNT+=(int) Floor (p[i]/m); if(cnt<f) r=m; ElseL=m; } printf ("%.4lf\n", L); }    return 0;}
View Code

C-sub-pie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.