zoukankan      html  css  js  c++  java
  • [JZOJ 5885] [NOIP2018模拟9.27] 物理实验 解题报告 (思维)

    题目链接:

    https://jzoj.net/senior/#main/show/5885

    题目:

    题解:

    把$a$数组按升序排序

    我们可以枚举$x$,发现对于任意$x$,最优情况下$y$一定等于$x+1$

    那么我们就是在一直$x$和$y$的前提下找$z$

    可以证明,在合法范围内,计算结果随着$a_z$的增大而单调增

    证明就是化简一下这个式子$frac{a_{z+1}-a_y}{a_{z+1}-a_x}>frac{a_z-z_y}{a_z-a_x}(a_{z+1}>a_z>a_y>a_x)$,发现是正确的。反之如果是小于号就是不正确的

    但是我写的代码它WA了,A掉的代码比我多一句话。但是我查看了结果发现我的输出没有错,和AC代码对拍也没有毛病,当然精度也没有问题...我觉得是OJ出了锅

    下面是我的代码

    #include<algorithm>
    #include<cstring>
    #include<cstdio>
    #include<iostream>
    using namespace std;
    
    const int N=1e5+15;
    int n,T;
    long double ans;
    double m;
    double a[N];
    int main()
    {
        freopen("atom.in","r",stdin);
        freopen("atom2.out","w",stdout);
        scanf("%d",&T);
        while (T--)
        {
            scanf("%d%lf",&n,&m);ans=-1;
            for (int i=1;i<=n;i++) scanf("%lf",a+i);
            sort(a+1,a+1+n);
            int id=1;
            for (int i=1;i<n-1;i++)
            {
                for (id=max(id,i+2);id<n&&a[id+1]-a[i]<=m;id++);
                if (a[id]-a[i]<=m) ans=max(ans,(long double)(a[id]-a[i+1])/(a[id]-a[i]));
            }
            if (ans==-1) puts("-1");
            else printf("%.13lf
    ",(double)ans);
        }
        return 0;
    }
  • 相关阅读:
    Python--day72--ajax简介
    Python基础1 介绍、基本语法
    10-Python-字符编码
    09-Python-集合
    07-Python-字符串操作
    99-Python-深浅拷贝
    06-Python-字典
    05-Python-判断语句
    04-Python-元组
    03-Python-操作列表
  • 原文地址:https://www.cnblogs.com/xxzh/p/9803208.html
Copyright © 2011-2022 走看看