非常好理解的搜索,但要注意几个地方的浮点误差,能用整数尽量用整数……
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
double sqr;
double dfs(double x,double y,int r)
{
if(r==1)
return x>y?x/y:y/x;
double ans=1e9;
double i=sqr/x;
int j=1;double q=i;
while(j<=r/2)
{
double dq=max(dfs(x,i,j),dfs(x,y-i,r-j));
ans=min(ans,dq);j++;i+=q;
}
i=sqr/y;
j=1;q=i;
while(j<=r/2)
{
double dq=max(dfs(i,y,j),dfs(x-i,y,r-j));
ans=min(ans,dq);j++;i+=q;
}
return ans;
}
int main()
{
double x,y;int n;
cin>>x>>y>>n;
sqr=(x*y)/(double)n;
double i=sqr/x;
int j=1;
printf("%.6lf",dfs(x,y,n));
return 0;
}