P10679 『STA - R6』spec

P10679 『STA - R6』spec - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

一个小题,我们知道如果 \(na = b\) 则有 \(b - 1 < na \le b\),而对于此题,\(1\) 一定满足题意但不一定为最大。于是,对于每个 x 都有一个 n,使得 \(x - 1 < na \le x\),我们只需要这样列式子,然后找到最大的全部合法区间(通过特定的枚举方式)即可。

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;

int n, m;
double g[N];

double dfs(int x, int s, double l, double r)
{
    if (l > r) return 0;
    if (x > n)
    {
        // cout << x << ' ' <<a n << endl;
        return r;
    }
    
    
    for (int i = s; i <= g[x]; i ++ )
    {
        
        double tx  = (g[x] - 1) / i, ty = g[x] / i;
        if (ty < l || tx >= r) continue;
        // cout << g[x] << ' ' << l << ' ' << r << ' ' << tx << ' ' << ty << endl;
        double t = dfs(x + 1, i + 1, max((g[x] - 1) / i, l), min((g[x]) / i, r));
        if (t) return t;
    }
    return 0;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> g[i], g[i] ++ ;
    sort(g + 1, g + 1 + n);
    n = unique(g + 1, g + 1 + n) - (g + 1);
    // cout << n << endl;
    double t = dfs(1, 1, 1, g[1]);
    if (t) printf("%.6lf", t);
    else puts("1");
    return 0;
}
posted @ 2024-07-14 11:16  blind5883  阅读(1)  评论(0编辑  收藏  举报