题解:P10679 『STA - R6』spec

· · 题解

我们充分发挥人类智慧。猜测答案接近但不大于序列中的最小元素。

因此我们可以从最小元素开始,从大到小枚举答案。

这样速度快的飞起,最大的点都可以在 30ms 内完成。

#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
const double eps = 6e-6;
int n,x[N];
int main(){
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%d",&x[i]),x[i]++;
    sort(x+1,x+n+1);
    for(double ans = x[1]+1;ans >= eps;ans -= eps){
        bool flag = true;
        for(int j = 1;j<=n;j++){
            int now = x[j]/ans;
            if(ans*now <= x[j]-1){
                flag = false;
                break;
            }
        }
        if(flag){
            printf("%.7lf\n",ans);
            return 0;
        }
    }
    return 0;
}

record。总用时仅 52ms。