Statistics

Problem Statement for "FastSpider"

Problem Statement

Imagine an ideally elastic band of length 1 foot, one end of which is connected to a wall. A spider sits at the connected end, while the other end is carried by a man. At time 0, the man starts walking away from the wall, passing manSpeed feet per second. At the same moment, the spider (represented by a single point) starts crawling along the band, covering spiderSpeed feet per second.

Your program should return an int, representing the time in seconds, rounded to the nearest integer, when the spider will overtake the man. If this will never happen, return -1.

Definition

Class:
FastSpider
Method:
findTime
Parameters:
double, double
Returns:
int
Method signature:
int findTime(double spiderSpeed, double manSpeed)
(be sure your method is public)

Notes

  • Don't forget that while the man is walking he is stretching the band, which moves the spider with it.
  • All movement is continuous.

Constraints

  • spiderSpeed will be between 0.2 and 0.5, inclusive.
  • manSpeed will be between 1 and 5, inclusive.
  • The answer, prior to rounding, will not be within 0.01 of x.5 for any integer x.
  • If the spider will ever overtake the man, it will take 1 hour (3600 seconds) or less.

Examples

  1. 0.25

    1

    Returns: 54

  2. 0.5

    1

    Returns: 6

  3. 0.5

    4.8877377

    Returns: 3600

  4. 0.2

    1

    Returns: 147

  5. 0.47

    2.78

    Returns: 133

  6. 0.23237120490148247

    1.3861233623877531

    Returns: 280

  7. 0.4860346899195756

    2.1453090856549557

    Returns: 38

  8. 0.3893122084936773

    1.3775108049378084

    Returns: 24

  9. 0.22192978592904428

    1.2179259257344017

    Returns: 198

  10. 0.4337737603217932

    1.091448852734342

    Returns: 10

  11. 0.4614311459654846

    3.7619849110399772

    Returns: 923

  12. 0.37935574071561684

    1.7729609003439992

    Returns: 60

  13. 0.2865618752931029

    1.777203892905189

    Returns: 277

  14. 0.29099121644108056

    1.6774062722861003

    Returns: 189

  15. 0.45570150300173223

    2.80458595082542

    Returns: 168

  16. 0.3049742992182573

    1.5922319450854472

    Returns: 116

  17. 0.4216300548816815

    3.223493194659371

    Returns: 648

  18. 0.46503486836221286

    3.8548576573670252

    Returns: 1033

  19. 0.3617935378639448

    2.3538538806281015

    Returns: 284

  20. 0.4719693229540898

    3.5402887877668636

    Returns: 511

  21. 0.406814213831339

    1.4749308802703385

    Returns: 25

  22. 0.24517434438026817

    2.181079373387396

    Returns: 3348

  23. 0.3418729955154742

    2.2681865966398957

    Returns: 335

  24. 0.495274020717714

    3.4950643511536716

    Returns: 332

  25. 0.4884484221062418

    2.794435616043163

    Returns: 109

  26. 0.47

    2.78

    Returns: 133

  27. 0.25

    1.0

    Returns: 54

  28. 0.5

    4.8877377

    Returns: 3600


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: