fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. ios::sync_with_stdio(false);
  5. cin.tie(nullptr);
  6.  
  7. long long n, l, v1, v2, k;
  8. cin >> n >> l >> v1 >> v2 >> k;
  9.  
  10. double low = 0, high = double(l) / v1;
  11. int trips = (n + k - 1) / k;
  12.  
  13. for (int it = 0; it < 100; ++it) {
  14. double mid = 0.5*(low + high);
  15. // Tính D theo công thức
  16. double D = (v1 * v2 * (mid - double(l)/v1)) / (v1 - v2);
  17. if (D <= 0) {
  18. // Đi bộ cũng kịp
  19. high = mid;
  20. continue;
  21. }
  22. if (D > l) {
  23. // Cần đi buýt dài hơn quãng đường => không khả thi
  24. low = mid;
  25. continue;
  26. }
  27. // Thời gian buýt chạy tất cả các chuyến
  28. double tbus = (2.0 * trips - 1.0) * (D / v2);
  29. if (tbus <= mid) high = mid;
  30. else low = mid;
  31. }
  32.  
  33. cout << fixed << setprecision(9) << high << "\n";
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5308KB
stdin
3 6 1 2 1
stdout
5.000000000