AtCoder 🌈 AWC0104A Election of the Class President
題目的難度顏色使用 Luogu 上的分級,由簡單到困難分別為 🔴🟠🟡🟢🔵🟣⚫。
🔗 🌈 AWC0104A Election of the Class President
Problem Statement
題目簡述
班上有 位學生,第 位學生得到 票。
如果最高票只由一位學生取得,輸出該學生的編號;如果有多位學生並列最高票,則無法決定班長,輸出 。
Constraints
約束條件
- 所有輸入皆為整數
思路:一次遍歷
只需要知道兩件事:
- 目前看過的最高票數 ,以及其對應的編號(即 )
- 這個最高票目前出現的次數
按照題意模擬即可。若最高票只出現一次,輸出其編號;否則輸出 -1。
注意
初始值要設為比 的最小值還小的數,否則若所有票數都是 0,會誤判為有多位學生並列最高票。因為 ,可以將其設為 。
複雜度分析
- 時間複雜度:
- 空間複雜度:
Code
1 | def solve(): |
寫在最後
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





