There is a piece of cake. The length is X and the width is Y. Now there are n people who want to divide the cake and ensure that the area of the cake is equal. Evaluate a method to minimize the maximum value of the ratio of the long side to the short side of all cakes.
Train of Thought: There is no idea for getting this question. But with a close eye, (n <= 10), amount .. It can be messed up...
You can directly search for water. Three parameters are passed to indicate the current length and width, and the current block needs to be divided into several parts, and then the water can pass through without worrying about it ..
Code:
#include <cstdio>#include <cstring>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;int X,Y,cnt;double DFS(double x,double y,int step);int main(){cin >> X >> Y >> cnt;cout << fixed << setprecision(6) << DFS(X,Y,cnt) << endl;return 0;}double DFS(double x,double y,int step){if(step == 1) {if(x < y)swap(x,y);return x / y;}double _x = x / step,re = 10000.0;for(int i = 1;i < step; ++i) {double temp = DFS(_x * i,y,i);temp = max(temp,DFS(x - _x * i,y,step - i));re = min(re,temp);}double _y = y / step;for(int i = 1;i < step; ++i) {double temp = DFS(x,_y * i,i);temp = max(temp,DFS(x,y - _y * i,step - i));re = min(re,temp);}return re;}
Bzoj 1024 scoi 2009 happy birthday