A - 花壇の植え付け / Planting the Flower Bed 解説 by admin
GPT 5.2 HighOverview
This is a problem where you plant flowers at both ends and arrange the rest equally spaced, then determine whether the spacing is at least the minimum required distance \(K\).
Analysis
If you plant flowers at the left end \(0\) and right end \(W\) of the flower bed, arranging a total of \(N\) flowers at equal intervals, the spacing between adjacent flowers is uniquely determined.
- With \(N\) flowers, there are \(N-1\) adjacent intervals (gaps) in total.
- Since the total length is \(W\), the spacing in an equally spaced arrangement is $\( \frac{W}{N-1} \)$
The required condition is “this spacing is at least \(K\)”, i.e., $\( \frac{W}{N-1} \ge K \)$
Here, you could naively compute \(\frac{W}{N-1}\) using decimals (floating point) and compare, but floating point errors may cause incorrect judgments near the boundary (e.g., a value that should be exactly equal is evaluated as 0.999999…, etc.).
Therefore, we rearrange the inequality using only integers: $\( \frac{W}{N-1} \ge K \iff W \ge K(N-1) \)$ This way, we can reliably determine the answer using only integer comparison.
Examples
- When \(N=4, W=9, K=3\):
The minimum required width is \(K(N-1)=3\times 3=9\). Since \(W=9\), the answer is Yes (spacing is \(9/3=3\)).
- When \(N=4, W=8, K=3\):
\(K(N-1)=9 > 8\), so the answer is No (spacing is \(8/3 \approx 2.66\), which is insufficient).
Algorithm
- Read input \(N, W, K\).
- If \(W \ge K \times (N-1)\), output
Yes; otherwise, outputNo.
Complexity
- Time complexity: \(O(1)\)
- Space complexity: \(O(1)\)
Implementation Notes
It is safer to avoid floating point and use the integer comparison form \(W \ge K(N-1)\).
\(N-1\) will never be 0 due to the constraints (\(N \ge 2\)).
Source Code
import sys
def main():
N, W, K = map(int, sys.stdin.readline().split())
if W >= K * (N - 1):
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.2-high.
投稿日時:
最終更新: