Connection Status:
Competition Arena > ChemMix
SRM 117 · 2002-10-21 · by leelin
Class Name: ChemMix
Return Type: int
Method Name: partsChem
Arg Types: (int)
Problem Statement

Problem Statement

A machine is programmed to automatically mix two chemicals. The machine begins with Bowl A filled with 360000 units of chemical 1 and Bowl B filled with 360000 units of chemical 2. Define a "mix" as follows:

  1. The machine pours 120000 units of liquid from Bowl A to Bowl B and stirs Bowl B until the liquid is well mixed.
  2. The machine pours 120000 units of liquid from Bowl B to Bowl A and stirs Bowl A until the liquid is well mixed.

Given an int mixes, return the number of units of chemical 1 in Bowl B after the machine performs the above procedure mixes amount of times.

If the amount of chemical 1 that needs to make up the 120000 units for pouring is not an integer, then round down the number of chemical 1 units for pouring. For example, if there are 180001 units of chemical 1 out of 360000 in Bowl A, then to pour 120000 units into Bowl B, there should be 60000.33 units of chemical 1 in the 120000, so just consider the 120000 units to be 60000 parts chemical 1, 60000 parts chemical 2. Similarly, if there are 240001 units of chemical 1 out of 480000 in Bowl B, then to pour 120000 units back into Bowl A, there should be 60000.25 units of chemical 1, so just consider the 120000 units to be 60000 parts chemical 1, 60000 parts chemical 2.

Constraints

  • mixes is an int between 0 and 100, inclusive.
Examples
0)
0
Returns: 0

If there has not been any mixing done, then the amount of chemical 1 in Bowl B has not changed.

1)
1
Returns: 90000

After pouring from bowl A to bowl B, bowl A has 240000 units of chemical 1 and bowl B has 120000 units of chemical 1 (and 360000 parts chemical 2). Then, after pouring from bowl B to bowl A, 1/4 of the 120000 units are chemical 1 units, so 30000 chemical 1 units are returned to bowl A. Bowl B now has 120000 - 30000 = 90000.

2)
5
Returns: 174375
3)
100
Returns: 180000
4)
17
Returns: 179999

Submissions are judged against all 19 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ChemMix with a public method int partsChem(int mixes) · 19 test cases · 2 s / 256 MB per case

Submitting as anonymous