fork download
  1. #include <bits/stdc++.h>
  2. #define fto(i,a,b) for(int i = a; i <= b; ++i)
  3. #define fdto(i,a,b) for(int i = a; i >= b; --i)
  4. #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2*((begin) > end))
  5. #define ll long long
  6. #define ii int,int
  7. #define iii int,int,int
  8. #define ff first
  9. #define ss second
  10. #define sz(a) int(a.size())
  11. #define pb push_back
  12. #define pob pop_back
  13. #define mp make_pair
  14. #define mt make_tuple
  15.  
  16. #define fastIO ios_base::sync_with_stdio(0); cin.tie(0)
  17. #define gen rng(chrono::steady_clock::now().time_since_epoch().count())
  18. #define rd(x,y) (rng()%(y-x+1)+x)
  19.  
  20. using namespace std;
  21.  
  22. const int N = 1e2;
  23. const int M = 1e2;
  24. const int oo = 2e9;
  25.  
  26. long double a,b,v1,v2;
  27.  
  28. long double t(long double x) {
  29. return sqrtl(a*a + x*x)/v1 + (b-x)/v2;
  30. }
  31.  
  32. long double tertnary_search(long double left, long double right) {
  33. fto(i,1,100) {
  34. long double c,d;
  35. c = left + (right-left)/3;
  36. d = right - (right-left)/3;
  37. if (t(c) > t(d)) left = c;
  38. else right = d;
  39. }
  40.  
  41. return t(left);
  42. }
  43.  
  44. int main() {
  45. #define NAME "dichuyen"
  46. #ifndef ONLINE_JUDGE
  47. freopen(NAME".inp", "r", stdin);
  48. //freopen(NAME".out", "w", stdout);
  49. #endif // ONLINE_JUDGE
  50.  
  51. int t; cin >> t;
  52. while (t--) {
  53. cin >> a >> b >> v1 >> v2;
  54. long double ans;
  55. ans = tertnary_search(0,b);
  56.  
  57. cout << setprecision(6) << fixed << ans << '\n';
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5276KB
stdin
1
3 8 6 8
stdout
1.330719