Topic links
bzoj1024 Topic description Description
Windy's birthday, in order to celebrate his birthday, his friends helped him to buy a side length of X and Y, respectively, a rectangular cake. Now including windy, there are a total of N people to divide the big cake, asking everyone to get the same area of cake. Windy Solo, everything can only be parallel to one side of the cake (either side), and must be cut into two pieces of this piece of cake. In this way, to cut into n pieces of cake, windy must cut N-1 times. To make every piece of cake look beautiful, we require that the maximum value of the long and short sides of the N-piece cake be the smallest. Can you help windy to find out the ratio? Input
Contains three integers, X Y N. Output
Contains a floating-point number that retains 6 decimal places. Sample Input
5 5 5 Sample Output
1.800000 HINT
100% of the data, meet 1 <= x, y <= 10000; 1 <= N <= 10. Solving
Nothing to say, the search can be.
#include <cstdio> #include <cstring> #include <iostream> #include <
algorithm> #include <cmath> #include <queue> #include <vector> using namespace std;
int n,x,y;
Double Dfs (double x,double y,int N) {if (n==1) return max (x, y)/min (x, y);
Double ans=1000000007;
for (int i=1;i<n;i++) {ans=min (Ans,max (Dfs (x,y/n*i,i), DFS (x,y-y/n*i,n-i)));
Ans=min (Ans,max (Dfs (x/n*i,y,i), DFS (x-x/n*i,y,n-i)));
} return ans;
} int main () {scanf ("%d%d%d", &x,&y,&n);
printf ("%.6f\n", DFS (X,y,n));
return 0; }