
CP 每周编程挑战
CCC DSA 知识地图:从 Junior 到 Senior 的数据结构与算法
从 CCC Junior 到 Senior 的数据结构与算法路线图,涵盖模拟、字符串、网格、计数、前缀和、图搜索、贪心、并查集、最短路、动态规划及典型历史题。
CP 每周编程挑战
CCC DSA 知识地图:从 Junior 到 Senior 要掌握哪些数据结构与算法
从 Junior 到 Senior 梳理 CCC 常见 DSA 模型:simulation、字符串、grid、counting、prefix sum、graph search、greedy、DSU、最短路和 DP。
When students prepare for the CCC, they often ask: "Which algorithms do I need to know?" The useful answer is not a giant list of DSA names. The useful answer is a roadmap of patterns: simulation, strings, arrays, grids, counting, prefix sums, graph search, greedy, DSU, shortest paths, and dynamic programming.
This article organizes the common CCC data structures and algorithms from Junior to Senior. It is designed as a study map for students and as a parent-friendly overview of how contest programming grows from careful implementation into algorithmic modeling.
本路线图涵盖的知识与学习基础
- 学习范围:Junior 到 Senior
- 核心内容:数据结构与算法规划、题型识别和竞赛准备
- 前置知识:Python/C++ 基础、数组/列表、循环、字符串、函数和调试
- What this teaches: Organize CCC problems into a reusable study path instead of treating each problem as isolated.
- Where it appears again: CP Weekly solutions, Python/C++ Notes, CCC contest review plans
What to Study Next
- Related CP Weekly problems: CCC 2026 J4 Snail Path, CCC 2024 J5 Harvest Waterloo, CCC 2020 J5/S2 Escape Room, CCC 2017 S1 Sum Game
- Related Python / C++ foundations: loops, strings, lists/vectors, dictionaries/maps, sets, 2D arrays, functions, debugging
- Related DSA roadmap articles: CCC Grid Problems, CCC Counting Patterns, CCC Prefix and Sliding Window Patterns, CCC Senior Graph Toolkit, CCC Dynamic Programming Roadmap
How to Read This Roadmap
CCC preparation has three layers:
| 阶段 | Goal | Common contest range |
|---|---|---|
| 基础 | Read carefully, implement simulation, handle input/output and edge cases | Junior J1-J3, Senior S1 |
| 建模 | Turn the problem into arrays, strings, grids, graphs, or states | Junior J4-J5, Senior S1-S2 |
| 算法选择 | Use constraints to choose the right pattern | Senior S3-S4 |
The key is to ask:
- What complexity does the input size allow?
- What structure is the problem really about?
- What state should I store so I do not repeat work?
Foundation: Implementation Before Fancy Algorithms
Junior problems train careful implementation. This stage includes conditionals, loops, accumulation, simulation, and edge cases.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| Condition tables | Choose output based on signs, scores, or rules | CCC 2017 J1 Quadrant Selection, CCC 2024 J1 Conveyor Belt Sushi |
| Loops and accumulation | Maintain totals, counts, and best values | CCC 2017 J2 Shifty Sum, CCC 2025 J2 Donut Shop |
| 模拟 | Update state exactly as the story says | CCC 2016 J4 Arrival Time, CCC 2026 J4 Snail Path |
| 边界情况 | Handle zero, boundaries, all-same input, exact equality | CCC 2017 J3 Exactly Electrical, CCC 2017 S1 Sum Game |
Many later mistakes come from this layer: wrong update order, missing boundary cases, or misunderstood input.
Strings and Parsing
CCC often uses strings as lightweight data structures. Students need to scan, slice, count, compare, and parse.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| String traversal | Scan characters and update state | CCC 2019 J3 Cold Compress, CCC 2025 J3 Product Codes |
| Substrings and rotations | Check whether a shifted or sliced pattern appears | CCC 2020 J4 Cyclic Shifts |
| Palindrome and pattern checks | Enumerate or verify string structure | CCC 2016 J3 Hidden Palindrome |
| Two-pointer basics | Use two positions to track a range or mismatch | CCC 2024 J4 Troublesome Keys, CCC 2025 J4 Sunny Days |
The goal is to extract structure from text before writing loops.
Arrays, Lists, and Grids
Once the problem has days, positions, scores, or cells, students need arrays and grids.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| Array traversal | Scan values and maintain totals or extremes | CCC 2021 S1 Crazy Fencing, CCC 2017 S1 Sum Game |
| Array transformation | Rotate, flip, or rearrange stored state | CCC 2019 J4 Flipper, CCC 2018 J4 Sunflowers |
| 网格坐标 | Represent positions with (r, c) or (x, y) |
CCC 2026 J4 Snail Path, CCC 2023 J4/S1 Trianglane |
| 网格相邻关系 | Reason about neighbors, boundaries, and perimeter | CCC 2023 J4/S1 Trianglane |
Grid problems are a major bridge from Junior to Senior because a grid can become a graph.
Counting: Frequency, Sets, and Parity
Counting is often the first moment when students see the value of a data structure.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 频率统计 | Count how often each value appears | CCC 2016 S1 Ragaman, CCC 2024 J3 Bronze Count |
| Sets | Check membership and constraints quickly | CCC 2022 J4/S2 Good Groups |
| 配对计数 | Count combinations with frequency arrays | CCC 2017 J5/S3 Nailed It! |
| 奇偶性 | Track odd/even instead of exact counts | CCC 2021 J5/S2 Modern Art |
Modern Art is the classic example: the full grid is unnecessary if we track row and column parity.
Prefix Sum and Sliding Window
Prefix thinking appears when a problem involves repeated ranges, consecutive segments, or cumulative state.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 累计前缀和 | Keep only the current cumulative value | CCC 2017 S1 Sum Game |
| 前缀数组 | Precompute sums for fast range queries | CCC 2020 S4 Swapping Seats |
| 差分数组 | Compress many interval updates | CCC 2026 J5/S2 Beams of Light |
| 滑动窗口 | Maintain a valid consecutive window | CCC 2020 S3 Searching for Strings, CCC 2025 J4 Sunny Days |
| 中心扩展 | Expand from a center and compare states | CCC 2023 S2 Symmetric Mountains |
Sunny Days is a good transition problem: it can be explained with prefix/suffix streaks or as a sliding window with one correction.
Sorting and Greedy
Greedy problems are not just "do the obvious thing." Students must learn why a local choice is safe.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 排序 | Put data into an order that makes comparison easy | CCC 2016 J5/S2 Tandem Bicycle |
| 贪心选择 | Choose the best current option | CCC 2013 J4 Time on Task |
| 贪心分配 | Assign resources to compatible positions | CCC 2015 S3 Gates |
| 贪心构造 | Build an output that satisfies the rule | CCC 2017 S2 High Tide, Low Tide |
Gates also leads naturally to DSU because repeatedly searching for an available gate is too slow.
Graph Search
Graph problems often come from grids, pages, relationships, or state transitions.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| DFS/BFS reachability | Decide whether one node can reach another | CCC 2018 J5 Choose Your Own Adventure, CCC 2013 S4 Who is Taller |
| 连通区域搜索(Flood Fill) | Visit an entire reachable region | CCC 2024 J5 Harvest Waterloo |
| 网格 BFS | Search a grid with movement rules or hazards | CCC 2018 S3 RoboThieves |
| 隐式图 | Generate edges from the rule instead of reading them directly | CCC 2020 J5/S2 Escape Room |
| 多源 BFS | Start search from multiple sources at once | Senior 网格图专题 |
Escape Room is a strong bridge problem: the graph is not given directly, but the rule creates edges.
二分答案
Some Senior problems ask for an optimal value that is hard to compute directly but easy to test.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 二分查找 | Search inside an ordered range | Foundation array practice |
| 二分答案 | Guess an answer, then check feasibility | CCC 2010 S3 Firehose |
| Convex or unimodal reasoning | Use cost structure to locate an optimum | CCC 2021 S3 Lunch Concert |
The key question is:
Can we do it with answer = X?
If feasibility is monotonic, binary search becomes available.
并查集与最小生成树
Disjoint Set Union maintains connected components under merges.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 并查集的查找与合并 | Maintain components efficiently | CCC 2015 S3 Gates |
| Kruskal 最小生成树 | Sort edges and connect components | CCC 2010 S4 Animal Farm |
| 最小生成树类问题处理 | Group edges and reason about connection cost | CCC 2023 S4 Minimum Cost Roads |
| 部分分策略 | Build simpler correct versions first | CCC 2017 S4 Minimum Cost Flow |
Think of DSU when the problem repeatedly merges things or asks whether two items are already connected.
Weighted Shortest Paths and State Graphs
When edges have different costs, plain BFS is not enough.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| Dijkstra | Shortest path with nonnegative edge weights | CCC 2009 S4 Shop and Ship |
| 扩展状态图 | Include extra information inside the node state | CCC 2015 S4 Convex Hull, CCC 2025 S4 Floor Is Lava |
| 0-1 BFS | Special shortest path when edge weights are 0 or 1 | Senior 网格图专题 |
The key modeling question is: does position alone describe the state, or do we need extra information such as damage, mode, or remaining resource?
动态规划
Dynamic programming is about state, transition, and order.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 记忆化搜索 | Store recursive search results | CCC 2015 J5 Pi Day |
| 网格动态规划 | Transition from neighboring positions | CCC 2025 J5 Connecting Territories, CCC 2012 S5 Mouse Journey |
| 有向无环图动态规划 | Accumulate answers along directed dependencies | CCC 2007 S4 Waterpark |
| 区间动态规划 | Solve smaller intervals before larger ones | CCC 2016 S4 Combining Riceballs |
| 滚动数组 | Keep only the previous layer when possible | CCC 2025 J5 Connecting Territories |
Connecting Territories is a good first DP example because each row only depends on the previous row.
Constructive Search and Constraint Propagation
Some Senior problems require analyzing constraints before writing code.
| DSA idea | Summary | Typical CCC problems |
|---|---|---|
| 带剪枝的枚举 | Enumerate states but stop impossible branches | CCC 2013 J5 Chances of Winning |
| 状态空间搜索 | Treat each configuration as a state | CCC 2015 J5 Rule of Three |
| 约束传播 | Use restrictions to infer missing values | CCC 2019 S3 Arithmetic Square |
| 构造算法 | Directly build a valid answer | CCC 2023 S3 Palindromic Poster, CCC 2024 S3 Swipe |
These problems reward thinking before coding. The first step is often to reduce the search space.
Recommended Study Order
- 模拟与边界情况
- 字符串与解析
- 数组、列表与网格
- 频率统计、集合与奇偶性
- 前缀和与滑动窗口
- 排序与贪心推理
- DFS/BFS、连通区域搜索与图的表示
- 二分答案
- 并查集与最小生成树
- Dijkstra 与状态图
- 动态规划
- 构造搜索与约束传播
For each topic, pair one explanation with two to four historical problems. Then review mistakes by type: reading error, edge case, state definition, implementation bug, or complexity mismatch.
常见错误
- Practicing only by year instead of by DSA pattern.
- Reading solutions without rewriting the code.
- Knowing BFS but failing to recognize graph models.
- Learning DP as a template instead of defining state and transition.
- Ignoring constraints and choosing the wrong complexity.
- Treating all wrong answers the same instead of classifying the error.
Review Questions
- What DSA patterns appear most often in Junior J4/J5?
- Why can many grid problems become graph search problems?
- What is the difference between prefix sum and sliding window?
- When should DSU come to mind?
- What are the three core questions in dynamic programming?
- If
N = 500000, which algorithmic approaches should you rule out first?
准备 CCC 时,很多学生会问:“我到底要学哪些算法?”关键是理解不同题型背后的模型:什么时候适合模拟或图搜索,什么时候需要前缀和、贪心、并查集或动态规划,而不是死记一张很长的算法清单。
这篇文章把 CCC Junior 到 Senior 常见的数据结构与算法整理成一张路线图。它适合学生用来查漏补缺,也适合家长理解:从 J1/J2 的基础实现,到 J4/J5 的建模,再到 S3/S4 的算法选择,能力是怎样一层一层长出来的。
本路线图涵盖的知识与学习基础
- 学习范围:Junior 到 Senior
- 核心内容:数据结构与算法规划、题型识别和竞赛准备
- 前置知识:Python/C++ 基础、数组/列表、循环、字符串、函数和调试
- 学习重点:把零散的 CCC 真题整理成可复习的 DSA 学习路径。
- 相关应用:CP Weekly 真题题解、Python/C++ Notes、CCC 赛前复习计划
下一步推荐
如果你正在规划 CCC 学习路径,可以配合下面这些文章阅读:
- 相关 CP Weekly 真题:CCC 2026 J4 Snail Path、CCC 2024 J5 Harvest Waterloo、CCC 2020 J5/S2 Escape Room、CCC 2017 S1 Sum Game
- 相关 Python/C++ 基础:循环、字符串、列表/向量、字典/映射、集合、二维数组、函数和调试
- 相关算法专题:CCC 网格题、计数方法、前缀和与滑动窗口、Senior 图论工具,以及动态规划路线图
这张地图应该怎么读
CCC 的 DSA 学习顺序大致可以分成三层:
| 阶段 | 目标 | 常见题位 |
|---|---|---|
| 基础 | 读懂题、写对基础模拟、处理输入输出和边界 | Junior J1-J3, Senior S1 |
| 建模 | 把题目转化为数组、字符串、网格、图或状态模型 | Junior J4-J5, Senior S1-S2 |
| 算法选择 | 根据数据范围与限制选择合适的算法 | Senior S3-S4 |
真正重要的不是“我学过多少算法名词”,而是看到题目后能回答三个问题:
- 输入规模暗示什么复杂度?
- 题目对象应该建模成什么结构?
- 我需要保存哪些状态,才能避免重复工作?
Junior 基础层:先把实现能力打稳
Junior 前半部分常考直接实现,但它不是“简单语法题”。它在训练学生把文字条件翻译成代码步骤。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 条件判断与分类 | 根据坐标、分数、规则输出不同结果 | CCC 2017 J1 Quadrant Selection, CCC 2024 J1 Conveyor Belt Sushi |
| 循环与累加 | 逐项处理输入,维护累计值、计数和最优值 | CCC 2017 J2 Shifty Sum, CCC 2025 J2 Donut Shop |
| 模拟 | 按题意一步一步更新状态 | CCC 2016 J4 Arrival Time, CCC 2026 J4 Snail Path |
| 边界情况 | 处理 0、边界、全相同、刚好相等 | CCC 2017 J3 Exactly Electrical, CCC 2017 S1 Sum Game |
这一层最容易被低估。很多 J4/J5 的错误,不是算法不会,而是状态更新顺序、边界、输入解析不稳。
字符串与解析:把文本当作结构化数据
CCC Junior 很喜欢把字符串当成轻量数据结构。学生需要会扫描、切片、计数、比较和解析数字。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 字符串遍历 | 一个字符一个字符扫描并更新状态 | CCC 2019 J3 Cold Compress, CCC 2025 J3 Product Codes |
| 子串与循环移位 | 判断某段字符串是否出现或循环移动 | CCC 2020 J4 Cyclic Shifts |
| 回文与模式匹配 | 枚举或检查字符串结构 | CCC 2016 J3 Hidden Palindrome |
| 双指针入门 | 用两个位置描述当前检查范围 | CCC 2024 J4 Troublesome Keys, CCC 2025 J4 Sunny Days |
这一类题的核心不是写很多代码,而是先把“字符串里的信息”拆出来。比如 Product Codes 不是简单读字符,而是扫描字母段和数字段;Cold Compress 不是压缩算法模板,而是连续段计数。
数组、列表与网格:从一维状态到二维状态
当题目需要记录每一天、每个位置或每个格子的信息时,就需要用数组或网格保存状态。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 一维数组遍历 | 扫描列表,维护最大值、最小值、差值或累计值 | CCC 2021 S1 Crazy Fencing, CCC 2017 S1 Sum Game |
| 数组变换 | 对数组或矩阵做旋转、翻转、重排 | CCC 2019 J4 Flipper, CCC 2018 J4 Sunflowers |
| 网格坐标 | 用 (r, c) 或 (x, y) 表示位置 |
CCC 2026 J4 Snail Path, CCC 2023 J4/S1 Trianglane |
| 网格相邻关系 | 判断上下左右相邻、边界、周长 | CCC 2023 J4/S1 Trianglane |
网格题是从 Junior 走向 Senior 的重要桥梁。刚开始是在格子里模拟,后来则会把每个格子看作图中的节点。
计数:频率、集合与奇偶性
很多 CCC 题看起来需要模拟,实际上只需统计关键信息。掌握计数方法后,学生会明显体会到:选择合适的数据结构,可以大幅简化代码。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 频率统计 | 统计每个值出现多少次 | CCC 2016 S1 Ragaman, CCC 2024 J3 Bronze Count |
| 集合成员判断 | 快速判断是否出现过、是否违反限制 | CCC 2022 J4/S2 Good Groups |
| 配对计数 | 用频率数组统计组合 | CCC 2017 J5/S3 Nailed It! |
| 奇偶性 | 只关心奇偶,不关心具体次数 | CCC 2021 J5/S2 Modern Art |
Modern Art 是典型例子:维护整张画布既慢又复杂;只记录每一行和每一列是否被翻转了奇数次,就能用公式计算答案。
前缀和、差分数组与滑动窗口
当题目涉及反复查询区间、连续段或累计状态时,可以考虑前缀和等预处理方法。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 累计前缀和 | 只维护当前累计值 | CCC 2017 S1 Sum Game |
| 前缀数组 | 预处理前缀,快速回答区间问题 | CCC 2020 S4 Swapping Seats |
| 差分数组 | 对多个区间更新做压缩 | CCC 2026 J5/S2 Beams of Light |
| 滑动窗口 | 维护一个满足条件的连续窗口 | CCC 2020 S3 Searching for Strings, CCC 2025 J4 Sunny Days |
| 中心扩展 | 从中心向外扩展比较状态 | CCC 2023 S2 Symmetric Mountains |
Sunny Days 可以用前后缀连续段计数解决,也可以使用允许一次修正的滑动窗口。它很适合帮助 Junior 学生初步理解如何维护窗口状态。
排序与贪心:先排序,再做局部选择
解决贪心题时,不能只凭直觉做选择。真正需要说明的是:为什么当前的局部选择不会破坏整体最优解?
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 排序 | 先把数据排成容易比较的顺序 | CCC 2016 J5/S2 Tandem Bicycle |
| 贪心选择 | 每次选择当前最合适的元素 | CCC 2013 J4 Time on Task |
| 贪心分配 | 把资源分配给能接受它的最大/最小位置 | CCC 2015 S3 Gates |
| 贪心构造 | 构造一个满足条件的输出 | CCC 2017 S2 High Tide, Low Tide |
Tandem Bicycle 很适合作为 Junior 到 Senior 的过渡题:排序后再配对,就能看清求最大或最小速度的策略。Gates 则进一步引出并查集,因为每次寻找可用登机口都进行线性扫描会太慢。
图搜索:从网格到图
图的概念初听起来可能有些抽象。在 CCC 中,图通常来自网格相邻关系、页面或节点之间的连接,以及状态转移关系。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| DFS/BFS 可达性搜索 | 判断能不能从 A 到 B | CCC 2018 J5 Choose Your Own Adventure, CCC 2013 S4 Who is Taller |
| 连通区域搜索(Flood Fill) | 找出从起点可达的一整片区域 | CCC 2024 J5 Harvest Waterloo |
| 网格 BFS | 在网格上求最短路或判断可达性 | CCC 2018 S3 RoboThieves |
| 隐式图 | 边不直接给出,需要由规则生成 | CCC 2020 J5/S2 Escape Room |
| 多源 BFS | 从多个起点同时扩散 | Senior 网格图专题 |
Escape Room 是很好的过渡题:移动并非沿网格的四个方向进行,而是根据格子中的数字,跳到坐标乘积符合条件的位置。这说明图不一定由题目直接给出,有时需要自己建立模型。
二分答案
Senior S3/S4 经常出现一种题型:答案本身不是直接算出来的,但可以猜一个答案,再判断它是否可行。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 二分查找 | 在有序范围中查找目标 | 基础语言与数组训练 |
| 二分答案 | 先假设一个答案,再检查它是否可行 | CCC 2010 S3 Firehose |
| 凸性与单峰性质分析 | 根据代价函数结构寻找最优点 | CCC 2021 S3 Lunch Concert |
这类题的关键是把问题拆成两层:
Can we do it with answer = X?
如果 X可行,并且可行性在数值增大或减小时具有单调性,就可以使用二分查找。
并查集与最小生成树:维护连通性
并查集(Disjoint Set Union,DSU)是 Senior 图论中的常见数据结构,适合判断两个点是否属于同一个连通分量,以及合并两个连通分量。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 并查集的查找与合并 | 快速维护连通块 | CCC 2015 S3 Gates |
| Kruskal 最小生成树 | 按边权排序,逐步连接组件 | CCC 2010 S4 Animal Farm |
| 最小生成树类问题处理 | 分组边、判断连通性、处理成本 | CCC 2023 S4 Minimum Cost Roads |
| 部分分策略 | 先写能拿部分分的模型 | CCC 2017 S4 Minimum Cost Flow |
并查集的难点在于识别适用场景:遇到不断合并关系、检查可用位置或建立最小连接结构的问题时,可以从连通分量的角度思考。
带权最短路与状态图
当边有不同代价,普通 BFS 就不够了。Senior S4 常常要求 Dijkstra,甚至要求把状态扩展成 (node, extra_state)。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| Dijkstra | 边权非负的最短路 | CCC 2009 S4 Shop and Ship |
| 扩展状态图 | 节点不只是位置,还包含额外状态 | CCC 2015 S4 Convex Hull, CCC 2025 S4 Floor Is Lava |
| 0-1 BFS | 边权只有 0 和 1 的特殊最短路 | Senior 网格图专题 |
状态图是 Senior 的难点之一。需要先判断:仅用位置表示节点,信息是否足够?如果不够,就把其他必要条件纳入状态。
动态规划:状态、转移与计算顺序
DP 是 CCC Senior 的核心之一,但不要一上来背模板。先问三个问题:
state表示什么?transition从哪里来?- 计算顺序如何保证依赖已经完成?
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 记忆化搜索 | 递归搜索中保存结果 | CCC 2015 J5 Pi Day |
| 网格动态规划 | 从相邻位置转移 | CCC 2025 J5 Connecting Territories, CCC 2012 S5 Mouse Journey |
| 有向无环图动态规划 | 按依赖方向累计答案 | CCC 2007 S4 Waterpark |
| 区间动态规划 | 对区间长度从小到大转移 | CCC 2016 S4 Combining Riceballs |
| 滚动数组 | 只保留必要层,降低空间 | CCC 2025 J5 Connecting Territories |
Connecting Territories 是很好的动态规划入门题:每一行只依赖上一行,因此可以使用滚动数组。Combining Riceballs 则涉及更典型的区间动态规划。
构造、约束传播与搜索
有些 Senior 题无法直接套用图算法或动态规划,需要先分析约束,再构造答案或缩小搜索空间。
| DSA 点 | 概要 | 典型历史考题 |
|---|---|---|
| 带剪枝的枚举 | 枚举可行状态,但及时剪枝 | CCC 2013 J5 Chances of Winning |
| 状态空间搜索 | 把每个局面看作一个状态 | CCC 2015 J5 Rule of Three |
| 约束传播 | 根据限制逐步推导未知量 | CCC 2019 S3 Arithmetic Square |
| 构造算法 | 直接构造满足条件的答案 | CCC 2023 S3 Palindromic Poster, CCC 2024 S3 Swipe |
这一类题很考“读题后的第一步”。如果直接写代码,很容易陷入复杂分支;如果先找约束,题目往往会变清楚。
一条推荐学习路线
如果学生从 Junior 走向 Senior,可以按这个顺序复习:
- 模拟与边界情况
- 字符串与解析
- 数组、列表与网格
- 频率统计、集合与奇偶性
- 前缀和与滑动窗口
- 排序与贪心推理
- DFS/BFS、连通区域搜索与图的表示
- 二分答案
- 并查集与最小生成树
- Dijkstra 与状态图
- 动态规划
- 构造搜索与约束传播
这个顺序不是绝对的。更实际的做法是:每学一个知识点,就配 2-4 道历史题。先看一个讲解,再独立做一道相似题,最后复盘错因。
常见误区
- 只按年份刷题,不按 DSA 模型复盘。
- 只看懂题解,不重写代码。
- 学过 BFS,却不能识别题目中的图模型。
- 学了 DP,但每道题都想套同一个模板。
- 忽略数据范围与限制,导致选择的算法复杂度不合适。
- 不总结错题类型:读题错、边界错、状态定义错、复杂度错,是完全不同的问题。
复习问题
- Junior J4/J5 最常见的 DSA 模型有哪些?
- 为什么网格题经常可以转化为图搜索问题?
- 前缀和与滑动窗口有什么区别?
- 什么情况下应该想到 DSU?
- 动态规划需要考虑哪三个核心问题?
- 如果一道题的输入规模是
N = 500000,你会首先排除哪些算法?
有问题或建议?
如果你对本文有疑问,或希望提出改进建议,请给我们发送私密留言。
有问题或建议?
如果你对本文有疑问,或希望提出改进建议,请给我们发送私密留言。