http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2374
思路:三分枚举。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define maxn 1000100
using namespace std;
const double eps=1e-;
const double pi=acos(-1.0); double w,h; double ok(double x,int flag)
{
double max1=;
double k=h;
double s=w;
double r=(x>s)?s:x;
double ss=pi*(r/)*(r/);
double ll=pi*r;
double c=k-x;
double r1=(k-x)>s?s:(k-x);
if(s>=ll&&flag==)
{
double v1=ss*c;
max1=max(max1,v1);
}
if(c>=ll&&flag==)
{
double v2=ss*s;
max1=max(max1,v2);
}
double s1=pi*(r1/)*(r1/);
double l1=pi*r1;
if(s>=l1&&flag==)
{
double v3=s1*x;
max1=max(v3,max1);
}
if(x>=l1&&flag==)
{
double v4=s1*s;
max1=max(max1,v4);
}
return max1;
} int main()
{
while(scanf("%lf%lf",&w,&h)!=EOF)
{
if(w==&&h==) break;
double l=,r=h;
double ans=,ans1=;
while(r-l>eps)
{
double mid1=(r+l)/;
double mid2=(l+mid1)/;
if(ok(mid1,)>=ok(mid2,))
{
ans=mid1;
l=mid2;
}
else
r=mid1;
}
l=,r=w;
while(r-l>eps)
{
double mid1=(r+l)/;
double mid2=(l+mid1)/;
if(ok(mid1,)>=ok(mid2,))
{
ans1=mid1;
l=mid2;
}
else
r=mid1;
}
printf("%.3lf\n",max(ok(ans,),ok(ans1,)));
}
return ;
}