fork download
  1. #include "bits/stdc++.h"
  2.  
  3. #define clr(x) memset((x), 0, sizeof(x))
  4. #define all(x) (x).begin(), (x).end()
  5. #define pb push_back
  6. #define mp make_pair
  7. #define in(x) int (x); input((x));
  8. #define x first
  9. #define y second
  10. typedef int itn;
  11.  
  12. #define next next12345
  13. #define prev prev12345
  14. #define x1 x12345
  15. #define y1 y12345
  16.  
  17. using namespace std;
  18.  
  19. template <typename T>
  20. T gcd(T x, T y) {
  21. while (y > 0) {
  22. x %= y;
  23. swap(x, y);
  24. }
  25. return x;
  26. }
  27.  
  28. template <class _T> inline _T sqr(const _T& x) {return x * x;}
  29. template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();}
  30.  
  31. typedef long double ld;
  32. typedef long long ll;
  33. typedef unsigned long long ull;
  34. typedef pair < int, int > PII;
  35. const long double PI = 3.1415926535897932384626433832795L;
  36.  
  37. template<typename T>
  38. inline void input(T &a) {
  39. static int c;
  40. a = 0;
  41. while (!isdigit(c = getchar()) && c != '-') {}
  42. char neg = 0;
  43. if (c == '-') {
  44. neg = 1;
  45. c = getchar();
  46. }
  47. while (isdigit(c)) {
  48. a = 10 * a + c - '0';
  49. c = getchar();
  50. }
  51. if (neg) a = -a;
  52. }
  53.  
  54. template <typename T = int>
  55. inline T nxt() {
  56. T res;
  57. input(res);
  58. return res;
  59. }
  60.  
  61. double a, b, p, q, v1, v2;
  62.  
  63. double eps = 1e-9;
  64.  
  65. double get(double x1, double y1, double x2, double y2) {
  66. double a = (v2 * v2 - v1 * v1);
  67. double b = (y1 - y2) * v1;
  68. double c = -(sqr(x1 - x2) + sqr(y1 - y2));
  69. if (fabs(c) < eps) return 0;
  70. if (fabs(a) < eps) {
  71. //cerr << -c / 2 / b << endl;
  72. return -c / 2 / b;
  73. }
  74. double d = b * b - a * c;
  75. if (d < 0) {
  76. return 1e9;
  77. }
  78. double t1 = (-b + sqrt(d)) / a;
  79. return t1;
  80. }
  81.  
  82.  
  83. double get2(double qq) {
  84. int it = 200;
  85. double l = qq / v1, r = 1e9;
  86. while (it--) {
  87. double mid = (l + r) / 2;
  88. double t1 = get(p, qq, -a, b) + get(-a, b, -a, 0) + get(-a, 0, p, qq - mid * v1);
  89. double t2 = get(p, qq, a, b) + get(a, b, a, 0) + get(a, 0, p, qq - mid * v1);
  90. double t = min(t1, t2);
  91. if (t < mid) {
  92. r = mid;
  93. } else {
  94. l = mid;
  95. }
  96. }
  97. return l;
  98. }
  99.  
  100. int main() {
  101. //#define int long
  102. #ifdef LOCAL
  103. freopen("input.txt", "r", stdin);
  104. //freopen("output.txt", "w", stdout);
  105. #else
  106. #define fname "war"
  107. freopen("input.txt", "r", stdin);
  108. freopen("output.txt", "w", stdout);
  109. #endif
  110.  
  111. a = nxt();
  112. b = nxt();
  113. p = nxt();
  114. q = nxt();
  115. v1 = nxt();
  116. v2 = nxt();
  117.  
  118.  
  119. double L = 0, R = (q - b) / v1;
  120.  
  121. int it2 = 200;
  122.  
  123. while (it2--) {
  124. double mid = (L + R) / 2;
  125. if (get2(q - v1 * mid) > 5e8) {
  126. R = mid;
  127. } else {
  128. L = mid;
  129. }
  130. }
  131. double l = 0, r = R;
  132.  
  133. int it = 200;
  134. while (it--) {
  135. double m1 = (2 * l + r) / 3;
  136. double m2 = (l + 2 * r) / 3;
  137. double vv1 = get2(q - v1 * m1);
  138. double vv2 = get2(q - v1 * m2);
  139. if (vv1 < vv2) {
  140. r = m2;
  141. } else {
  142. l = m1;
  143. }
  144. }
  145.  
  146. cout << setprecision(10) << fixed;
  147. cout << get2(q - v1 * l) << endl;
  148.  
  149.  
  150. #ifdef LOCAL
  151. //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
  152. #endif
  153. return 0;
  154. }
Time limit exceeded #stdin #stdout 5s 3096KB
stdin
Standard input is empty
stdout
Standard output is empty