Luogu 🟠 P14358 [CSP-J 2025] 座位
🔗 🟠 P14358 [CSP-J 2025] 座位
Problem Statement
題目簡述
考場共有 名考生,每位考生的第一輪成績皆不相同。所有考生將按照成績由高到低,以蛇形分配的方式安排在 個 row 與 個 column 的座位中。
具體蛇形分配規則如下:
- 成績第 高到第 高的考生,依序安排在第 個 column 的第 個 row 到第 個 row。
- 成績第 高到第 高的考生,依序安排在第 個 column 的第 個 row 到第 個 row(即 row 號反向)。
- 成績第 高到第 高的考生,依序安排在第 個 column 的第 個 row 到第 個 row。
- 依此類推。
給定考場的 row 數 與 column 數 ,以及所有考生的成績 (其中 為目標考生小 R 的成績),求小 R 的座位在第幾個 column 與第幾個 row。
Constraints
約束條件
- 所有 互不相同
思路:模擬與週期性映射
將所有成績由高到低排序後,目標考生在排序序列中的索引(從 開始)即代表其排名。
考場座位按 column 填充,每個 column 容納 個座位。將一維索引 拆成二維:
- (column,從 開始)
- (row,從 開始)
座位的蛇形規則:偶數 column( 為偶數)由上到下填充,row 即為 ;奇數 column 由下到上填充,row 需反轉為 。最後將 分別 即得答案。
按 column 蛇形填充、row 數為 時,一維索引 :
用 c & 1 判斷奇偶並反轉 row,是蛇形矩陣 / S 型曲線的通用技巧。
複雜度分析
- 時間複雜度:(瓶頸在排序)
- 空間複雜度:(儲存成績陣列)
Code
1 | def solve(): |
寫在最後
The cover image was created by @4AUB. 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.



![Luogu 🟡 P14359 [CSP-J 2025] 异或和](https://i.pixiv.cat/img-master/img/2026/06/21/14/33/23/146273507_p0_master1200.jpg)
