[SCOI2009]生日快乐

题目地址:

https://ac.nowcoder.com/acm/problem/20272

基本思路:

由于,所以我们考虑直接暴力;
我们用double dfs(double x,double y,int k)表示将长为,宽为的矩阵切成块的最小长宽比;
对于每次切,这时的每块蛋糕的面积一定是确定的
而我们一定是平行切,也就是说我们切长的时候切出来的一定要是的倍数,切宽的时候一定要是的倍数,
所以我们枚举每种切法,然后将切出来的两个剩余部分继续就可以了。

参考代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define ll long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 1e9

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

double dfs(double a,double b,int k) {
  if (a < b) swap(a, b);
  if (k == 1) return a / b;
  double res = INF; //长宽比取min;
  for (int i = 1; i <= k / 2; i++) { //枚举切法;
    double na = a * (double) i / (double) k, nb = b * (double) i / (double) k;
    //两部分的结果要取max,这种切法的结果取min;
    res = min(res, max(dfs(na, b, i), dfs(a - na, b, k - i))); // 对长切后将两个剩余部分继续切;
    res = min(res, max(dfs(a, nb, i), dfs(a, b - nb, k - i)));// 对宽切后将两个剩余部分继续切;
  }
  return res;
}
int x,y,n;
signed main() {
  scanf("%d%d%d", &x, &y, &n);
  double ans = dfs((double) x, (double) y, n);
  printf("%.6lf", ans);
  return 0;
}