TestingCar
SRM 276 · 2005-12-08 · by Olexiy
Problem Statement
A test driver in a car company tests a new prototype. For each test drive, he is given a list of restrictions, limiting his speed at certain moments in time. The test driver wants to reach as fast a speed as possible. You should write a program which will find the maximal speed he can reach without violating the restrictions.
You will be given a
At the start of the test drive, the car is motionless. Given two
Notes
- The car does not have to come to a complete stop at the final moment of the test drive. It can still be moving.
- For the purposes of the problem you may assume the car has no speed limit at all.
- Your return value must have an absolute or relative error less than 1e-9.
Constraints
- restrictions will contain between 0 and 50 elements, inclusive.
- Each element of restrictions will be formatted as "S T D".
- In each element of restrictions, S, T and D will be separated by single spaces and contain no leading zeroes.
- In each element of restrictions, S will be an integer between 0 and 100, inclusive.
- In each element of restrictions, T will be an integer between 0 and duration, inclusive.
- In each element of restrictions, D will be an integer between 0 and 1000, inclusive.
- duration will be between 1 and 1000, inclusive.
- acceleration will be between 1 and 25, inclusive.
{"30 0 200"}
100
25
Returns: 30.0
The restriction doesn't allow us to go faster than 30 meters per second.
{"30 0 200"}
4
5
Returns: 20.0
We only have enough time to reach 20 meters per second.
{"50 0 40", "50 60 50"}
100
10
Returns: 150.0
The car can go above 50 meters per second only between the 40th and 60th second. Accelerating from the 40th to 50th second, and braking from the 50th to 60th allows you to reach 150 meters per second.
{"50 30 10", "50 60 50"}
100
10
Returns: 175.0
{"50 30 10", "50 60 50"}
100
14
Returns: 235.0
Submissions are judged against all 222 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TestingCar with a public method double maximalSpeed(vector<string> restrictions, int duration, int acceleration) · 222 test cases · 2 s / 256 MB per case