1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int>pii;
#define debug(x) std:: cerr << #x << " = " << x << std::endl; const int maxn=2e5+10,inf=0x3f3f3f3f,mod=1000000007; const double eps=1e-7; signed main(signed argc, char const *argv[]) { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int t; cin>>t; while(t--) { double n,p1,v1,p2,v2; cin>>n>>p1>>v1>>p2>>v2; if(p1>p2) { swap(p1,p2); swap(v1,v2); } double l=0,r=min({(n+min(n-p1,p1))/v1,(n+min(n-p2,p2))/v2,max((n-p1)/v1,p2/v2)}); double ans=r; while(r-l>eps) { double mid=(l+r)/2; auto f=[](double p,double v,double t){ double d=v*t; if(d<p) return (double)0; return max(max(p,d-2*p+p),p+(d-p)/2); }; double s1=f(p1,v1,mid)+f(n-p2,v2,mid); double s2=f(n-p1,v1,mid)+f(p2,v2,mid); if(s1>=n||s2>=n) ans=min(ans,mid),r=mid; else l=mid; } cout<<setiosflags(ios::fixed)<<setprecision(9)<<ans<<endl; } return 0; }
|