TopCoder problem "FastSpider" used in SRM 243 (Division II Level Three)



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

0)
    
0.25
1
Returns: 54
1)
    
0.5
1
Returns: 6
2)
    
0.5
4.8877377
Returns: 3600
3)
    
0.2
1
Returns: 147
4)
    
0.47
2.78
Returns: 133

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4004

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7218&pm=4004

Writer:

Olexiy

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Brute Force, Math