【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e835
【TOI 新手同好會 歷屆考題】
- 入場卷的座位編號 N (1 <= N <= 10,000)
- 為了方便除法取整與取餘後的判斷,我們先把座號減 1(即從 0 開始編號,zero-based indexing),計算後的結果再加 1 還原。因為每排第幾位是從 1 開始, 由左至右數。
- 從 0 開始編號: zero-based indexing
- 從 1 開始編號: one-based indexing
#include <iostream>
using namespace std;
int n;
int main() {
cin >> n;
if (n <= 2500){
cout << 1 << " " << (n-1)/25+1 << " " << (n-1)%25+1 << "\n";
}
else if (n <= 7500){
n -= 2500;
cout << 2 << " " << (n-1)/50+1 << " " << (n-1)%50+1 << "\n";
}
else{
n -= 7500;
cout << 3 << " " << (n-1)/25+1 << " " << (n-1)%25+1 << "\n";
}
}
Python code (credit: Amy Chou)
N = int(input())
# 轉為 zero-based
N -= 1
if N < 2500:
#第一大區, 每排各有 25 人
print(f"1 {N // 25 + 1} {N % 25 + 1}")
elif N < 7500:
#第二大區,每排各有 50 人
N -= 2500
print(f"2 {N // 50 + 1} {N % 50 + 1}")
else:
#第三大區, 每排各有 25 人
N -= 7500
print(f"3 {N // 25 + 1} {N % 25 + 1}")