dfs(x,y,n)表示长为x,宽为y,切n块
每次砍的一定是x/n的倍数或者y/n的倍数
#include<bits/stdc++.h> using namespace std; const int inf=1e9; int x,y,n; double dfs(double x,double y,int n) { if(n==1)return max(x,y)/min(x,y); double sum=1.0*inf; double xx=x/n,yy=y/n; for(int i=1;i<=(n>>1);i++) sum=min(sum,max(dfs(xx*i,y,i),dfs(x-xx*i,y,n-i))), sum=min(sum,max(dfs(x,yy*i,i),dfs(x,y-yy*i,n-i))); return sum; } int main() { scanf("%d%d%d",&x,&y,&n); printf("%.6lf ",dfs(1.0*x,1.0*y,n)); }