BZOJ1024 - [SCOI2009]生日快乐

2016/12/07

祝自己生快!

代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int _oo_ = 1E9;
double x, y;
int N;

double dfs(double x, double y, int N) {
    double ans = _oo_;
    double ratio = max(x, y) / min(x, y);
    double R = double(1)/double(N);
    if(N == 1) return ratio;
    for(int i=1;i<N;i++) {
        double a = max(dfs(x * i * R, y, i), dfs(x * (N-i)* R, y, N-i));
        double b = max(dfs(x, y * i * R, i), dfs(x, y * (N-i) * R, N-i));
        ans = min(ans, min(a, b));
    }
    return ans;
}

int main() {
    scanf("%lf %lf %d", &x, &y, &N);
    double ans = dfs(x, y, N);
    printf("%.6lf", ans);
}