Connection Status:
Competition Arena > WaterLevel
SRM 196 · 2004-05-27 · by dgoodman · Math
Class Name: WaterLevel
Return Type: double
Method Name: netAmt
Arg Types: (int, int, vector<int>)
Problem Statement

Problem Statement

The lake where we vacation sometimes floods. As soon as the level reaches the maximum level that can be contained by the banks of the lake, the additional water covers a fixed floodplain area, which enlarges the area of the lake. Below are views of the lake from the side, with water indicated by X's.

   |              |          |              |
   |___        ___|          |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 int[] rain, the amounts of rain that fell on each day during our vacation. The method returns the net increase (a positive value) or decrease (a negative value) in the units of water in the lake during our vacation. The i-th element of rain tells how many units of water fell during the entire i-th day. You should assume that it rains at a constant rate throughout the day.

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
Examples
0)
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.

1)
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.

2)
20
40
{0}
Returns: -20.0
3)
20
40
{1}
Returns: -19.0
4)
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
6)
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.

Coding Area

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

Submitting as anonymous