WaterLevel
SRM 196 · 2004-05-27 · by dgoodman
Problem Statement
| | | |
|___ ___| |XXXXXXXXXXXXXX|
| | |XXXXXX|
| | |XXXXXX|
|XXXXXX| |XXXXXX|
|XXXXXX| |XXXXXX|
(not flooded) (flooded)
The amount of evaporation depends on the surface area. When the lake is not
flooded, the evaporation is evapNormal units of water per day. When the lake is
flooded, the evaporation is evapFlood units per day. The lake never goes dry and never
extends beyond the floodplain.
Assume that the lake is initially full but not flooded. Create a class WaterLevel
that contains a method netAmt that is given evapNormal, evapFlood, and
Notes
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- evapNormal will be between 0 and 1000 inclusive
- evapFlood will be between evapNormal and 1000 inclusive
- rain will contain between 1 and 50 elements inclusive
- each element of rain will be between 0 and 1000 inclusive
20
40
{0,60,0,0}
Returns: -35.0
After the first day, 20 units have evaporated so we are 20 units below flood stage. After the first half of the second day, 30 units of rain have fallen while 10 units have evaporated, so we have reached flood stage. By the end of the day another 30 have fallen and 20 (40 / 2) have evaporated leaving us 10 units above flood stage. On the third day, we leave flood stage after 1/4 of a day. By the end of the day we are 15 units below flood stage. On the fourth day 20 units evaporate leaving us 35 units below flood stage.
20
39
{0,60}
Returns: 10.5
After the first day, we are 20 units below flood stage. We reach flood stage after half of the next day. During the last half of the day 30 units of rain fall while 19.5 units evaporate.
20
40
{0}
Returns: -20.0
20
40
{1}
Returns: -19.0
287
912
{1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0}
Returns: -14125.0
200
800
{0,600}
Returns: 0.0
After the first day, the level is 200 below flood stage due to evaporation. Halfway through the second day, 300 units have rain have fallen and 100 units have evaporated so we have just reached flood stage. After that we are at a stable equilibrium in which the level does not change.
Submissions are judged against all 27 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class WaterLevel with a public method double netAmt(int evapNormal, int evapFlood, vector<int> rain) · 27 test cases · 2 s / 256 MB per case