TopcoderArchive
SRM17 May 2005
SRM 243

FastSpider

Problem statement, definition, constraints, and public examples.

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
Back to all problems