fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct path {
  5. double time;
  6. double velocity;
  7. double length;
  8. };
  9.  
  10. void calc_length (struct path *s1);
  11. double solve (double half_path,
  12. struct path s1,
  13. struct path s2,
  14. struct path s3);
  15.  
  16. int main() {
  17. struct path s1, s2, s3 ;
  18. double half_path;
  19.  
  20. cin >> s1.time >> s2.time >> s3.time;
  21. cin >> s1.velocity >> s2.velocity >> s3.velocity;
  22.  
  23. calc_length(&s1);
  24. calc_length(&s2);
  25. calc_length(&s3);
  26.  
  27. half_path = (s1.length + s2.length + s3.length)/2;
  28. cout << solve( half_path, s1, s2, s3) << endl;
  29.  
  30. return 0;
  31. }
  32.  
  33. void calc_length (struct path *s){
  34. s->length = s->time*s->velocity;
  35. }
  36.  
  37. double solve (double half_path,
  38. struct path s1,
  39. struct path s2,
  40. struct path s3){
  41.  
  42. if (half_path <= s1.length) {
  43. return half_path/s1.velocity ;
  44. }
  45. else if (half_path <= (s1.length + s2.length)) {
  46. return s1.time + (half_path - s1.length)/s2.velocity ;
  47. }
  48. else {
  49. return s1.time + s2.time + (half_path - s1.length - s2.length);
  50. }
  51. }
Success #stdin #stdout 0s 3480KB
stdin
4.5 75.9 3.124
100 0 0

-9 85 3
450 230 20

2 3 4
90 80 30
stdout
2.25