F - Lipschitz Constant Kattis - 思维

  • F - Lipschitz Constant

  •  Kattis - lipschitzconstant 
  • 题意:求 L  是L对所给出的所有的x,f(x)都满足 |f(x)−f(y)|≤L⋅|x−y|.
  • 思路:也就是 求一个|f(x)−f(y)|/|x−y|.最大值,几何上来看就是斜率最大值,按照x排个序,相邻的越近了斜率越大
  • #include<bits/stdc++.h>
    using namespace std;
    #define maxn 215005
    int n,i;
    double ans;
    struct node
    {
        double x,y;
    } a[maxn];
    bool cmp(node c,node d)
    {
        return c.x<d.x;
    }
    int main()
    {
        scanf("%d",&n);
        i=0;
        ans=-1e15;
        for(int i=0; i<n; i++)
            scanf("%lf%lf",&a[i].x,&a[i].y);
        sort(a,a+n,cmp);
        for(int i=1; i<n; i++)
            ans=max(fabs(a[i].y-a[i-1].y)/fabs(a[i].x-a[i-1].x),ans);
        printf("%.5lf\n",ans);
        return 0;
    }
    
  •  

猜你喜欢

转载自blog.csdn.net/BePosit/article/details/84069535