AtCoder 🌈 AWC0104B Bus Arrival Time
題目的難度顏色使用 Luogu 上的分級,由簡單到困難分別為 🔴🟠🟡🟢🔵🟣⚫。
🔗 🌈 AWC0104B Bus Arrival Time
Problem Statement
題目簡述
有 條公車路線會經過同一個站牌。第 條路線的公車會在 分鐘時到站。
高橋只想搭乘到站時間不早於 的公車,求所有路線中最早能搭到的到站時間。
Constraints
約束條件
- 輸入皆為整數
思路:計算每條路線的下一班車
每條路線的到站時間都是公差固定的倍數序列,所以只要算出這條路線第一個不小於 的倍數即可。
Tip
若班距是 ,最早不小於 的班次可以寫成
在整數運算中, 可用 的整除形式計算。
把每條路線各自算出的候選到站時間取最小值,就是答案。若 ,所有路線在時間 都有車,因此公式也會自然得到 。
複雜度分析
- 時間複雜度:
- 空間複雜度:
Code
1 | from math import inf |
寫在最後
Cover Image Credit
The cover image was created by @Rosuuri. All rights belong to the original artist.
It is used here only as a non-commercial cover illustration for this note. I do not claim ownership of the artwork.
If you are the copyright holder and believe this usage is inappropriate, please contact me by email or leave a comment. I will remove the image promptly.
本部落格所有文章除特別聲明外,均採用CC BY-NC-SA 4.0 授權協議。轉載請註明來源 十六個天亮!
評論
WalineGiscus





