返回学习页
知识点指南
Arrays
Array problems are about positions and values in a sequence. The main decision is what to remember while scanning: a count, best value, previous value, current streak, or another compact state.
什么时候使用
读题时可以留意这些信号。
- The input is a sequence of numbers, labels, positions, or scores.
- The answer depends on neighbours, ranges, counts, or positions.
- A single pass or a sorted pass can keep enough information.
常见错误
提交前可以检查这些小陷阱。
- Mixing one-based and zero-based positions.
- Reading outside the array bounds.
- Initialising best or answer to a value that fails on negative inputs.
怎么写成代码
把知识点翻译成变量、循环、判断和更新。
- Read values into a vector/list when you need positions, neighbours, sorting, or multiple passes.
- Use a loop index when the position matters.
- Use a direct value loop when only the value matters.
- Store previous, current, best, count, or total depending on the story.
在 Block 题里长什么样
答题时通常会看到这些步骤被拆成代码块。
- 1Read N.
- 2Read the array.
- 3Initialise state from 0, first value, or a large/small sentinel.
- 4Loop over positions or values.
- 5Compare/update state.
- 6Print result.
题目里怎么出现
读题时先找这些信号,再决定答案区应该选哪些 blocks。
- The statement mentions first, last, neighbouring, consecutive, position, or list.
- The input gives N followed by N values.
- The answer can be discovered by scanning all records once.
Track a best value
一个小型模板,展示代码和 blocks 的对应关系。
C++
int best = values[0];
for (int i = 1; i < N; i++) {
if (values[i] > best) {
best = values[i];
}
}
cout << best << '\n';Python
best = values[0]
for i in range(1, N):
if values[i] > best:
best = values[i]
print(best)对应 block 顺序
- 1Read N and the array.
- 2Set best from the first value.
- 3Loop from the second position onward.
- 4Compare current value with best.
- 5Update best when needed.
- 6Output best.
相关题目
用题库中的相关题目练习这个知识点。
12 道题
Buried Treasure
2025 · 预计 18 分钟
入门
Javelin
2024 · 预计 15 分钟
入门
Election II
2022 · 预计 18 分钟
入门
Level Ground
2022 · 预计 22 分钟
入门
Off the Track
2025 · 预计 25 分钟
简单
TeleTrip
2023 · 预计 28 分钟
简单
Distincto's Raffle
2023 · 预计 30 分钟
简单
Tennis Robot II
2024 · 预计 40 分钟
中等
Atlantis III: Twin Rivers
2024 · 预计 45 分钟
中等
Beautiful Buildings
2022 · 预计 55 分钟
困难
Composing Pyramids
2022 · 预计 58 分钟
困难
Buildings
2025 · 预计 75 分钟
挑战