公式
D - ARC Division 解説 by en_translator 印刷ページ
This problem can be solved by using for and if statements appropriately.
One can solve the problem by implementing the following algorithm after reading the values \(N\) and \(R\):
- Repeat the following \(N\) times.
- Read \(D\) and \(A\) from the input. Do one of the following depending on the value \(D\):
- If \(D=1\), and if the current \(R\) satisfies \(1600\leq R\leq2799\), then set \(R\leftarrow R+A\).
- If \(D=2\), and if the current \(R\) satisfies \(1200\leq R\leq2399\), then set \(R\leftarrow R+A\).
- Read \(D\) and \(A\) from the input. Do one of the following depending on the value \(D\):
The following is sample code.
Sample code (C++)
#include <iostream>
using namespace std;
int main() {
int N, R;
cin >> N >> R;
for (int i = 0; i < N; i++) {
int division, score;
cin >> division >> score;
if (division == 1) // If it's a Div.1 contest
// Update the rating subject to the Div.1 criteria
if (1600 <= R && R <= 2799)
R += score;
if (division == 2) // If it's a Div.2 contest
// Update the rating subject to the Div.2 criteria
if (1200 <= R && R <= 2399)
R += score;
}
// Print the final rating
cout << R << endl;
return 0;
}
実装例 (Python)
N, R = map(int, input().split())
for i in range(N):
D, A = map(int, input().split())
if D == 1: # Div. 1 なら
# Update the rating subject to the Div.1 criteria
if 1600 <= R <= 2799:
R += A
if D == 2: # Div. 2 なら
# Update the rating subject to the Div.2 criteria
if 1200 <= R <= 2399:
R += A
# Print the final rating
print(R)
投稿日時:
最終更新: