A - エアコンの温度調整 / Air Conditioner Temperature Adjustment Editorial by admin
Qwen3-Coder-480BOverview
For each room whose temperature exceeds \(37\) degrees, perform cooling operations using the air conditioner as needed. Given that one operation lowers the temperature by \(0.1\) degrees, find the total number of operations required to make all rooms comfortable.
Analysis
In this problem, if each room’s temperature \(T_i\) exceeds \(37.0\), we need to run the air conditioner a number of times equal to the difference divided by \(0.1\).
For example, if a room’s temperature is \(37.5\) degrees, we need to lower it by \(37.5 - 37.0 = 0.5\) degrees, which requires \(0.5 / 0.1 = 5\) operations.
However, floating-point arithmetic can introduce errors. For instance, computing 0.5 / 0.1 in Python may yield a result like 4.999999999999999. Such errors risk producing a value that is \(1\) less than the correct number of operations.
To avoid this, we use the technique of adding a very small value (e.g., \(10^{-9}\)) to the result before converting it to an integer. This ensures we obtain the correct count.
Additionally, since each room can be processed independently, no complex algorithm is needed. We simply check the temperature difference for each room and sum up the required number of operations.
Algorithm
- Read the temperature \(T_i\) for each room.
- For each temperature, do the following:
- If \(T_i > 37.0\):
- Temperature excess: \( \text{excess} = T_i - 37.0 \)
- Required operations: \( \text{operations} = \left\lfloor \frac{\text{excess}}{0.1} + 10^{-9} \right\rfloor \)
- Add to the total.
- If \(T_i > 37.0\):
- Output the total number of operations.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(N)\)
Implementation Notes
- To avoid errors from floating-point division, it is necessary to add a small value (e.g., \(10^{-9}\)).
- Since each room’s temperature is given to one decimal place, direct comparison and subtraction are possible.
## Source Code
```python
n = int(input())
t = list(map(float, input().split()))
total_operations = 0
for temp in t:
if temp > 37.0:
excess = temp - 37.0
operations = int(excess / 0.1 + 1e-9) # Avoid floating point error
total_operations += operations
print(total_operations)
This editorial was generated by qwen3-coder-480b.
posted:
last update: