WaterAndOxygen
TCO17 Round 1B · 2017-03-31 · by cgy4ever
Problem Statement
Compute and return the longest amount of time (in days) your crew can survive. Note that the answer is not necessarily an integer.
Notes
- The returned value must have an absolute or relative error less than 1e-9.
Constraints
- costH2O will be between 1 and 1,000,000,000, inclusive.
- costO2 will be between 1 and 1,000,000,000, inclusive.
- remainH2O will be between 0 and 1,000,000,000, inclusive.
- remainO2 will be between 0 and 1,000,000,000, inclusive.
64 70 3 7 Returns: 12.0
If you don't do anything, after 70 / 7 = 10 days you will run out of oxygen. At that time you will have 64 - 10 * 3 = 34 moles of water left. In order to survive longer you will need to electrolyze some of your remaining water to produce the oxygen you need. To get enough oxygen for a day, you need to electrolyze 2 * 7 = 14 moles of water. Don't forget that you also need 3 moles of actual water per day. Thus, on each of the following days you will consume 17 moles of water, which means that you can survive for 34 / 2 = 2 extra days. In total you will survive for 10 + 2 = 12 days.
99 102 1 1 Returns: 99.0
You will run out of water after 99/1 = 99 days, while the oxygen will last for 102/1 = 102 days. Electrolysis won't help you live longer than 99 days.
101 99 1 1 Returns: 99.66666666666667
This time you should use 4/3 of a mole of water to produce 2/3 of a mole of oxygen.
123456789 987654321 123 456 Returns: 1003713.731707317
987654321 123456789 456 123 Returns: 1758643.7307692308
Submissions are judged against all 65 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WaterAndOxygen with a public method double maxDays(int remainH20, int remainO2, int costH2O, int costO2) · 65 test cases · 2 s / 256 MB per case