#P1984. Optimal Water Boiling Energy
Optimal Water Boiling Energy
Optimal Water Boiling Energy
We have a total of \(1\,kg\) water divided equally into \(n\) cups so that each cup contains \(1/n\,kg\) of water at an initial temperature of \(0^\circ C\). Your task is to ensure that each cup of water is "boiled" at least once. A cup is considered boiled once its temperature reaches \(100^\circ C\) (even if later its temperature drops through heat transfer operations).
You may perform two kinds of operations:
- Heating: You can heat any one cup. Heating a cup by \(t\) degrees requires an energy of \(\displaystyle \frac{4200\times t}{n}\,J\). Note that if a cup reaches \(100^\circ C\) (i.e. when \(t\) is such that the cup’s temperature becomes \(100^\circ C\)), it is considered boiled and its temperature will not exceed \(100^\circ C\) even if more energy is provided.
- Heat Transfer: At any time you may choose two cups with different temperatures and allow heat to transfer from the hotter cup to the cooler one. The heat transfer continues until the two cups reach the same temperature. Since the masses of water are equal, the temperature drop of the hotter cup equals the temperature gain of the cooler cup. There is no energy cost, no heat loss, and the cups do not mix.
A straightforward method would be to heat each cup individually from \(0^\circ C\) to \(100^\circ C\), incurring a total energy cost of \(4200\times100\,J\) per cup. However, by cleverly combining heating with heat transfer operations, the total energy consumption can be decreased.
For example, when \(n=2\) one optimal strategy is as follows:
- Heat the first cup from \(0^\circ C\) to \(100^\circ C\). The energy cost is \(\displaystyle \frac{4200\times100}{2}\,J\). (The cup is now boiled.)
- Perform a heat transfer between the hot cup (at \(100^\circ C\)) and the second cup (at \(0^\circ C\)). The two cups, having equal mass, will reach an equilibrium temperature of \(50^\circ C\). Although the first cup’s temperature drops, it is still considered boiled.
- Heat the second cup from \(50^\circ C\) to \(100^\circ C\); this requires \(\displaystyle \frac{4200\times50}{2}\,J\) of energy. Now the second cup is boiled as well.
The total energy used is \(4200\times75\,J\), which is a 25% saving compared to heating each cup separately.
In general, it can be shown that the optimal total energy required is given by
\[ E(n)=\frac{210000\times (n+1)}{n}\,J. \]Input: A single integer \(n\) representing the number of cups.
Output: The minimum total energy (in joules) required to boil every cup (each cup must have reached \(100^\circ C\) at least once). Output the answer as a number. If it is not an integer, print the result with at least 6 decimal places.
inputFormat
The input consists of one line containing an integer \(n\) (\(1 \le n \le 10^6\)), which is the number of cups.
outputFormat
Output a single number: the minimum total energy (in joules) required to boil every cup. If the answer is not an integer, print at least 6 decimal places.
sample
1
420000.000000