2015 HUAS Summer Trainning #4 C

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.
My friends are 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 (but 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 be of the same size.
What is the largest possible piece size all of us can get? All the pies are cylindrical in shape 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. Then for each test case:
• One line with two 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 that me and my friends can
all get a pie piece of size V . The answer should be given as a oating point number with an absolute
error of at 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

题目大意:给你N个蛋糕,k+1个人,问每个人能获得的最大体积的蛋糕是多少。

解题思路:m=选出最大的蛋糕体积/k+1人,p=全部蛋糕的体积和/k+1;

每次用m+p/2,来除以每个蛋糕的体积,如果人数相等或大于,这个体积就是最大的。

代码:

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstring>
 6 using namespace std;
 7 const double pi=acos(-1.0);
 8 const int maxn=10000+10;
 9 int main()
10 {
11     int T,N,F,i,c;
12     double l,r,mid,a[maxn],sum;
13     scanf("%d",&T);
14     while(T--)
15     {
16         memset(a,0,sizeof(a));
17         scanf("%d%d",&N,&F);
18         F++;
19         sum=0;
20         for(i=0;i<N;i++)
21         {
22             scanf("%d",&c);
23             a[i]=pi*c*c;
24             sum+=a[i];
25         }
26         sort(a,a+N);
27         l=a[N-1]/F;
28         r=sum/F;
29         while(r-l>1e-6)
30         {
31             int count=0;
32             mid=(l+r)/2;
33             for(i=0;i<N;i++)
34                 count+=(int)floor(a[i]/mid);
35             if(count>=F)
36                 l=mid;
37             else r=mid;
38         }
39         printf("%.4f\n",l);
40     }
41     return 0;
42 }

时间: 2024-08-26 01:40:52

2015 HUAS Summer Trainning #4 C的相关文章

2015 HUAS Summer Trainning #6~H

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

2015 HUAS Summer Trainning #4 B

Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so calledscribers. The scriber had been given a book and after several months he finished its copy. One of

2015 HUAS Summer Trainning #4 D

Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the minimalamount of them, such they would completely cover the segment [0, M]. InputThe first line is the number of test cases, followed by a blank line.Eac

2015 HUAS Summer Trainning #5~E

Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for

2015 HUAS Summer Trainning #4 A

Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input seque

2015 HUAS Summer Trainning #5~N

Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … The bone collector had a big bag with a volume of V ,and

2015 HUAS Summer Trainning #5~J

Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and if a and b are regul

2015 HUAS Summer Trainning #5 C

Description Let x and y be two strings over some finite alphabet A. We would like to transform x into y allowing only operations given below: Deletion: a letter in x is missing in y at a corresponding position. Insertion: a letter in y is missing in 

2015 HUAS Summer Trainning #5 B

Description 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉. 研究人员有n种类型的砖块,每种类型的砖块都有无限个.第i块砖块的长宽高分别用xi,yi,zi来表示. 同时,由于砖块是可以旋转的,每个砖块的3条边可以组成6种不同的长宽高. 在构建塔时,当且仅当A砖块的长和宽都分别小于B砖块的长和宽时,A砖块才能放到B砖块的上面,因为必须留有一