Statistics

Problem Statement for "Subway2"

Problem Statement

Subway trains can move people quickly from one station to the next. It is known that the distance between two consecutive stations is length meters. For safety, the train can't move faster than maxVelocity meters/sec. For comfort, the absolute acceleration can't be larger than maxAcceleration meters/sec^2. The train starts with velocity 0 meters/sec, and it must stop at the next station (i.e., arrive there with a velocity of 0 meters/sec). Return the minimal possible time to get to the next station.

Definition

Class:
Subway2
Method:
minTime
Parameters:
int, int, int
Returns:
double
Method signature:
double minTime(int length, int maxAcceleration, int maxVelocity)
(be sure your method is public)

Notes

  • Your return value must be accurate to within an absolute or relative tolerance of 1E-9.
  • If the train's speed at time 0 is v0 and the acceleration is always a, then at time t the speed will be (v0 + t * a) and the train will be (v0 * t + 0.5 * a * t^2) away.

Constraints

  • length, maxAcceleration and maxVelocity will each be between 1 and 1000, inclusive.

Examples

  1. 1

    2

    10

    Returns: 1.4142135623730951

    maxVelocity is very large. So the train can keep speeding up until it reaches position 0.5.

  2. 1

    1

    1

    Returns: 2.0

  3. 10

    1

    1

    Returns: 11.0

    The train reaches its maximum velocity after 1 second, while traveling 0.5 meters. It then travels the next 9 meters in 9 seconds, and takes 1 second to decelerate to 0 m/s while covering the final 0.5 meters.

  4. 1

    10

    1

    Returns: 1.1

  5. 1

    1

    1

    Returns: 2.0

  6. 1

    1

    1000

    Returns: 2.0

  7. 1

    1000

    1

    Returns: 1.001

  8. 1

    1000

    1000

    Returns: 0.06324555320336758

  9. 1000

    1

    1

    Returns: 1001.0

  10. 1000

    1

    1000

    Returns: 63.245553203367585

  11. 1000

    1000

    1

    Returns: 1000.001

  12. 1000

    1000

    1000

    Returns: 2.0

  13. 778

    887

    384

    Returns: 2.458961621570838

  14. 336

    794

    916

    Returns: 1.301036207838119

  15. 650

    493

    387

    Returns: 2.4645764213196637

  16. 28

    363

    422

    Returns: 0.5554637206007079

  17. 764

    60

    691

    Returns: 7.136759301905405

  18. 427

    541

    927

    Returns: 1.7768276368338702

  19. 212

    737

    173

    Returns: 1.4601689398514521

  20. 430

    568

    369

    Returns: 1.8149595404404748

  21. 863

    531

    783

    Returns: 2.549694416902874

  22. 136

    68

    124

    Returns: 2.8284271247461903

  23. 23

    803

    930

    Returns: 0.33848243845981674

  24. 168

    70

    59

    Returns: 3.690314769975787

  25. 12

    457

    394

    Returns: 0.32408767757678103

  26. 374

    230

    43

    Returns: 8.884630940343781

  27. 785

    920

    422

    Returns: 2.318885225633629

  28. 325

    199

    538

    Returns: 2.5559075328702554

  29. 414

    371

    316

    Returns: 2.1618786038418234

  30. 981

    92

    527

    Returns: 6.530863182845241

  31. 863

    874

    957

    Returns: 1.987374335793859

  32. 282

    997

    171

    Returns: 1.8206373506484366

  33. 85

    926

    306

    Returns: 0.6059460589441044

  34. 506

    337

    328

    Returns: 2.5159766953752625

  35. 314

    730

    847

    Returns: 1.3116965903765547

  36. 896

    125

    858

    Returns: 5.354624169818083

  37. 815

    546

    583

    Returns: 2.4657072487261167

  38. 365

    435

    368

    Returns: 1.8378248375812094

  39. 88

    751

    44

    Returns: 2.0585885486018642

  40. 179

    277

    809

    Returns: 1.6077429972251018

  41. 404

    585

    789

    Returns: 1.6620448737603815

  42. 400

    755

    652

    Returns: 1.455749050493678

  43. 677

    61

    933

    Returns: 6.662840432049294

  44. 13

    740

    369

    Returns: 0.2650854018430103

  45. 95

    587

    227

    Returns: 0.8052142980435125

  46. 571

    796

    540

    Returns: 1.7357993672064023

  47. 468

    379

    435

    Returns: 2.2224567451738775

  48. 903

    98

    602

    Returns: 6.07100838882165

  49. 653

    493

    318

    Returns: 2.698489545460344

  50. 281

    302

    757

    Returns: 1.9292107983928977

  51. 866

    442

    287

    Returns: 3.6667428697557822

  52. 620

    445

    690

    Returns: 2.360727368389914

  53. 32

    730

    441

    Returns: 0.41873913807217095

  54. 772

    98

    118

    Returns: 7.7464545140089935

  55. 710

    676

    482

    Returns: 2.1860467971224433

  56. 857

    568

    928

    Returns: 2.4566666985176546

  57. 587

    354

    498

    Returns: 2.575416153087093

  58. 684

    307

    966

    Returns: 2.98530603410502

  59. 529

    625

    220

    Returns: 2.7565454545454546

  60. 830

    733

    872

    Returns: 2.128222618600952

  61. 271

    20

    504

    Returns: 7.362064927722384

  62. 716

    709

    369

    Returns: 2.460830743709412

  63. 1

    2

    1

    Returns: 1.5

  64. 200

    300

    400

    Returns: 1.632993161855452

  65. 100

    3

    10

    Returns: 13.333333333333332

  66. 6

    1

    1

    Returns: 7.0

  67. 40

    3

    4

    Returns: 11.333333333333332


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: