*题意 公平地分披萨pie,有n个pie,找来f个朋友,加上自己那么总人数共f+1人
*解题思路 这是一个二分法的题目,不断进行二分演算就可以了,还要注意的就是精度的问题。
*AC源码
# include<iostream>
# include<iomanip>
using namespace std;
const double pi=3.14159265359;
const double esp=1e-6;
int main(void)
{
int test;
cin>>test;
while(test--)
{
int n,f;
cin>>n>>f;
double* v=new double[n+1];
f++;
double maxsize=0.0;
for(int i=1;i<=n;i++)
{
cin>>v[i];
v[i]*=v[i];
if(maxsize<v[i])
maxsize=v[i];
}
double low=0.0;
double high=maxsize;
double mid;
while(high-low>esp)
{
mid=(low+high)/2;
int count_f=0;
for(int i=1;i<=n;i++)
count_f+=(int)(v[i]/mid);
if(count_f < f)
high=mid;
else
low=mid;
}
cout<<fixed<<setprecision(4)<<mid*pi<<endl;
delete v;
}
return 0;
}
Pie
Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 224 Accepted Submission(s) : 59
3<br>3 3<br>4 3 3<br>1 24<br>5<br>10 5<br>1 4 2 3 4 5 6 5 4 2<br>
25.1327<br>3.1416<br>50.2655<br>