FastSpider
SRM 243 · 2005-05-17 · by Olexiy
SRM 243 · 2005-05-17 · by Olexiy · Brute Force, Math
Problem Statement
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 anint , representing the time in seconds, rounded to the nearest integer, when the spider will overtake the man. If this will never happen, return -1.
Your program should return an
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
Submissions are judged against all 28 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class FastSpider with a public method int findTime(double spiderSpeed, double manSpeed) · 28 test cases · 2 s / 256 MB per case