Questions: Make up your brain.
Idea: a binary answer.
But how to judge?
We define whether the recursive function judge (a, B, k) can be divided into k blocks for a cake with a length of A and B.
Each time, we only need to enumerate the division method, that is, the number of blocks and the number of blocks are divided into two parts, vertical cutting or vertical.
If k = 1, the system returns the result.
In this example, the current binary answer mid is used as the parameter.
In this way, you can.
Code:
#include <cstdio>#include <cstring>#include <cctype>#include <iostream>#include <algorithm>using namespace std;typedef double f2;int n;f2 ans, area;#define git(a, b) ((a)>(b)?(a)/(b):(b)/(a))bool dfs(f2 x, f2 y, f2 k) {if (k == 1)return git(x, y) <= ans;int i;for(i = 1; i < k; ++i)if (dfs(x, i * area / x, i) && dfs(x, y - i * area / x, k - i))return 1;for(i = 1; i < k; ++i)if (dfs(i * area / y, y, i) && dfs(x - i * area / y, y, k - i))return 1;return 0;}int main() {int x, y;scanf("%d%d%d", &x, &y, &n);area = x * y / (f2)n;f2 L = 0, R = 10000, mid;while(R - L > 1e-8) {mid = (L + R) / 2;ans = mid;if (dfs(x, y, n))R = mid;elseL = mid;}printf("%.6lf", L);return 0;}
Bzoj1024 [scoi2009] Happy birthday