[贪心]JZOJ 5885 物理实验
分析
贪心,用队列维护可行的z和x即可
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int N=1e5+10; int a[N]; int t,n,m; double f; int main() { freopen("atom.in","r",stdin); freopen("atom.out","w",stdout); scanf("%d",&t); while (t--) { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); f=0.0; int t=n; for (int i=n-2;i;i--) { while (a[i]+m<a[t]&&t>=i+2) t--; if (t==i+1) continue; f=max(f,(double)(a[t]-a[i+1])/(double)(a[t]-a[i])); } printf("%.9lf\n",f==0?-1:f); } fclose(stdin);fclose(stdout); }
在日渐沉没的世界里,我发现了你。