PrevNext

更多信息请参阅使用 MDX

操作步骤

  1. 派生(Fork) GitHub 仓库。

  2. 如果你要为模块中的题目添加题解,请不要新建文件。如果你要添加站内题解,且相应文件尚不存在,请在 solutions/<division>/ 中新建一个包含前置元数据的 mdx 文件。可以参考 solutions/silver/usaco-690.mdx

    ---
    id: usaco-690
    source: USACO Silver 2017 January
    title: Cow Dance Show
    author: (add your name here)
    ---
    
    [Official Analysis](http://www.usaco.org/current/data/sol_cowdance_silver_jan17.html)
    
    ## Explanation
    
    (add explanation here ...)
    
    Use `\texttt{}` around variable names with length *greater than one*, like so. Place long equations on separate lines with display math, and use `\cdot` instead of `*` to denote multiplication.
    
    $$
    \texttt{arr}[i]=2\cdot (a+b+c+d+e)+\sum_{j=0}^{i-1}\texttt{arr}[j]
    $$
    
    Some additional text styles which you might consider using:
    
    http://latexref.xyz/Font-styles.html
    
    https://web.archive.org/web/20220626025744/http://applied-r.com/latex-font-styles/
    
    $func(var)$
    
    $\textit{func(var)}$
    
    $\textrm{func(var)}$
    
    $\text{func(var)}$
    
    $\textsf{func(var)}$
    
    $\textbf{func(var)}$
    
    $\texttt{func(var)}$
    
    ## Implementation
    
    **Time Complexity:** $\mathcal{O}(N\log^2N)$
    
    ^ Format time complexity like this. Should appear outside of `<LanguageSection>` if it's the same for all implementations.
    
    If you need to link to a module, format your link like [this](/silver/binary-search) instead of [this](https://usaco.guide/silver/binary-search).
    
    <LanguageSection>
    
    <CPPSection>
    
    (add cpp code)
    
    </CPPSection>
    
    <PySection>
    
    (if you have Python code)
    
    </PySection>
    
    <JavaSection>
    
    (if you have Java code)
    
    </JavaSection>
    
    </LanguageSection>

    文件名和题解 ID 应保持一致。特别是,USACO 题目(如上例)的 ID 是 usaco.org 题目网址最末尾的数字。题解文件名应与其中题解的 ID 相同。更多 ID 示例请参阅使用 MDX

  3. 按照下文的规范添加你的实现。除非另一份同语言实现采用不同思路,或明显优于官方实现,否则无需再添加一份与官方实现语言相同的替代实现。

  4. 在模块的 .problems.json 文件中(本例为 Binary_Search.problems.json),将 solutionMetadata 设为 { "kind": "internal" }。你也可以添加标签。如果题目不属于任何模块,可以将它添加到 extraProblems.json如果题解包含提示,还应在 solutionMetadata 中注明。

    {
      "uniqueId": "usaco-690",
      "name": "Cow Dance Show",
      "url": "http://www.usaco.org/index.php?page=viewproblem2&cpid=690",
      "source": "Silver",
      "difficulty": "Easy",
      "isStarred": false,
      "tags": ["Binary Search", "Sorted Set"],
      "solutionMetadata": {
        "kind": "internal",
        // "hasHints": true
        // ^ uncomment the line above if the solution has hints
      }
    },
  5. 提交 Pull Request 前,请使用实时编辑器检查模块和题解能否正确渲染。

代码规范

代码会通过 pre-commit 自动格式化。我们希望代码清晰易懂。如果有代码无法编译或难以阅读,请联系我们。

贡献代码前,请阅读以下规范。

通用规范

  • 缩进会自动转换为制表符。

  • 通常不要包含未使用的代码(例如“模板”)。

    • 这条规则也有少数例外(例如使用 Java I/O 的 Kattio 类时)。遇到这种情况,请用 CodeSnip 将其折叠。
  • 使用大家都能理解的变量名,尤其是青铜组和白银组代码。变量名应比你在比赛中通常使用的名字更具描述性。

  • 在代码中适当添加注释来解释逻辑。你可以复制 USACO 官方题解的代码,再通过更具描述性的变量名和有帮助的注释加以改进。不过,请牢记 Google C++ 风格指南中的以下准则:

    请记住:虽然注释非常重要,但最好的代码本身就能说明含义。为类型和变量使用合理的名称,远胜于使用晦涩名称后再通过注释解释。


    通常,变量的实际名称应当足够清晰,让人能够大致了解它的用途。


    能够自我说明的代码不需要注释。

  • 不要重复自己。

  • 完成审查提出的修改后,请务必重新请求审查。

Python

  • 在代码中使用 snake_case 命名变量。
Resources
Google

Python 代码会使用 Black with tabs 自动格式化。

Module Progress:

PrevNext