标签:
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 12486 | Accepted: 4310 | 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
Source
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
const double PI = 3.14159265359;
const double eps = 1e-7;
double pie[100010];
int n,m;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
double maxx = 0;
for(int i=0;i<n;i++)
{
scanf("%lf",&pie[i]);
pie[i] *= pie[i];
if(maxx<pie[i])
{
maxx = pie[i];
}
}
m = m + 1;
double l = 0;
double r = maxx;
double mid;
while(r-l>eps)
{
mid = (r+l)/2;
int sum = 0;
for(int i=0;i<n;i++)
{
if(pie[i]-mid>eps)
{
sum += (int)pie[i]/mid;
}
}
if(sum>=m)
{
l = mid;
}
else
{
r = mid;
}
}
printf("%.4lf\n",mid*PI);
}
return 0;
}
版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。
标签:
原文地址:http://blog.csdn.net/yeguxin/article/details/47053045