首先还是说一下题意:就是“我”过生日,有很多的朋友来,我们一起分披萨,每个人分得的面积是一样的,并且只能是一块不能是很多快的面积的和。(如果一块切出来一部分后剩下的不能组成一块就当作是丢弃了、、、(浪费可耻啊!))
解题思路很简单,二分枚举面积找到一个面积的大小可以使所有人分得的那一块的大小一样。
Pie
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 8932 | Accepted: 3236 | Special Judge |
Description
![](https://i-blog.csdnimg.cn/blog_migrate/01c512ad8c76928fbf6834c9c6c4c1b8.jpeg)
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 ≤ 10 000: the number of pies and the number of friends.
- One line with N integers ri with 1 ≤ ri ≤ 10 000: 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 floating 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
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <cmath>
#define PI 3.1415926535898
const double esp=1e-6;
using namespace std;
int main()
{
int T, n, m, i;
double f[10100];
cin >>T;
while(T--)
{
cin >>n>>m;
m++;
double hight = 0.0;
double low = 0.0;
double mid;
for(i = 0; i < n; i++)
{
cin >>f[i];
f[i] *= f[i];
if(f[i] > hight)
hight = f[i];
}
while(hight - low > esp)
{
int sum = 0;
mid = (hight+low)/2;
for(i = 0; i < n; i++)
sum += (int)(f[i]/mid);
if(sum >= m)//这里写错了,写成了sum > m,错了。因为相同的时候是low = mid,看看是否可以分的块更大,所以low = mid。
low = mid;
else
hight = mid;
}
cout <<fixed<<setprecision(4)<<PI*mid<<endl;
}
return 0;
}