http://www.lydsy.com/JudgeOnline/problem.php?id=1024
对于一个矩形要么横着切,要么竖着切,对于竖着切的时候,枚举左半矩形的块数,横着也一样。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
const int maxn = 11000;
const double INF = 0x3f3f3f3f;
using namespace std;
int X,Y,N;
double solve(double x,double y,int k)
{
if(k==1) return max(x,y)/min(x,y);
double ans=INF;
for(int i=1;i<k;++i){
ans=min(ans,max(solve(x,y/k*i,i),solve(x,y/k*(k-i),k-i)));
}
for(int i=1;i<k;++i){
ans=min(ans,max(solve(x/k*i,y,i),solve(x/k*(k-i),y,k-i)));
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ONLINE_JUDGE
scanf("%d %d %d",&X,&Y,&N);
printf("%.6f\n",solve(X,Y,N));
return 0;
}
时间: 2024-11-12 08:48:12