GreedyGovernment
SRM 275 · 2005-11-30 · by NeverMore
Problem Statement
Create a class GreedyGovernment which contains a method maxAverageCost. You will be given a
Notes
- Your return value must have an absolute or relative error less than 1e-9.
Constraints
- tolls will contain between 2 and 10 elements, inclusive.
- Each element of tolls will contain the same number of characters as the number of elements in tolls.
- Each element of tolls will contain only the characters '1'-'9', inclusive, or the character 'X'.
- The i'th character of the i'th element of tolls will be 'X' for all i.
- tollHike will be between 1 and 100, inclusive.
{"X324", "XXX2", "12X5", "991X"}
9
Returns: 10.0
Note that there are 4 ways to travel from sector 0 to sector 3: sector 0 --> sector 3 sector 0 --> sector 1 --> sector 3 sector 0 --> sector 2 --> sector 3 sector 0 --> sector 2 --> sector 1 --> sector 3 Any other path from sector 0 to sector 3 (for example, sector 0 --> sector 2 --> sector 0 --> sector 3) visits a sector more than once, which is not allowed in your town.
{"X324", "5X22", "12X5", "991X"}
57
Returns: 29.2
{"X11", "2X1", "37X"}
76
Returns: 39.5
{"X32X", "XXXX", "XXXX", "XXXX"}
99
Returns: 0.0
There is no way to travel from sector 0 to sector 3.
{"X561324534", "1X82346123", "98X1641451", "982X412355", "9812X31235", "82359X8371", "283659X112", "9832465X12", "98246892X1", "982468926X"}
17
Returns: 33.75003877701846
Submissions are judged against all 76 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GreedyGovernment with a public method double maxAverageCost(vector<string> tolls, int tollHike) · 76 test cases · 2 s / 256 MB per case