A - 花壇の植え付け / Planting the Flower Bed 解説 by admin
Qwen3-Coder-480BOverview
A problem to determine whether, when planting \(N\) flowers in a flower bed of width \(W\) with one flower at each end and equally spaced, the interval between adjacent flowers is at least \(K\) centimeters.
Analysis
In this problem, we are required to arrange the flowers at equal intervals. Furthermore, it is determined that flowers are planted at both ends (positions \(0\) and \(W\)). This means there are a total of \(N - 1\) gaps between flowers, and all of these gaps have the same length.
Therefore, the interval between adjacent flowers can be calculated as:
\[ \text{interval} = \frac{W}{N - 1} \]
If this value is at least \(K\), the condition for healthy growth is satisfied.
For example, when \(N = 3\), \(W = 10\), \(K = 4\):
- The interval is \(10 / (3 - 1) = 5\) centimeters
- This satisfies the required minimum interval \(K = 4\), so the answer is
Yes
On the other hand, when \(N = 3\), \(W = 10\), \(K = 6\):
- The interval is \(5\) centimeters, but it does not satisfy the required minimum of \(6\), so the answer is
No
Also, when \(N = 1\), there is only one flower and there is no need to consider intervals, so the condition is always satisfied.
Algorithm
- Read \(N\), \(W\), \(K\) from input.
- If \(N = 1\), output
Yesand terminate. - Otherwise, compute the interval \(\text{interval} = \frac{W}{N - 1}\).
- If \(\text{interval} \geq K\), output
Yes; otherwise, outputNo.
Complexity
- Time complexity: \(O(1)\)
- Space complexity: \(O(1)\)
Implementation Notes
- Using floating-point numbers does not cause issues with comparisons (since the inputs are integers and the constraints are small).
- Be sure not to forget handling the case where \(N = 1\).
## Source Code
```python
N, W, K = map(int, input().split())
if N == 1:
print("Yes")
else:
interval = W / (N - 1)
if interval >= K:
print("Yes")
else:
print("No")
This editorial was generated by qwen3-coder-480b.
投稿日時:
最終更新: