MEGChai MEGChai
  • 文章
    • 随笔
    • 笔记
    • 教程
  • 关于
首页 › 数据结构与算法 › 《数据结构与算法》专题读者须知
精选

《数据结构与算法》专题读者须知

Chai
2021-11-24 0:00:00数据结构与算法阅读 372

算法题解统一使用现代 C++ / Python 3 作为默认使用的编程语言,基本原则如下:

  • 语法风格:Google C++ Style Guide / Google Python Style Guide
  • 相关工具:cpplint / pylint / clang format / autopep8 (部分规则有修改)
  • 在复杂度不存在巨大差异的情况下,算法实现的可读性(思路)优于极致的效率追求;
    • 不使用竞赛中常见的宏定义和变量命名风格(手速狗慎用此原则);
    • 不排斥使用 bits/stdc++.h 这样的头文件,不排斥使用 using namespace std;
    • 不排斥使用标准库(STL)中的常见接口,不认识的请查文档如 cppreference, 当作学习语法;
    • 默认一开始不做卡常数级别优化,一些题会给出无法 AC 的情况并解释,过早优化是万恶之源;
    • 默认不禁用 C++ 标准流同步,不做 I/O 层面的优化(除非数据量巨大)。

想要快速跳转 OJ 题解,可在地址栏按此模式输入 URL(将 xxx 替换成题目编号):

  • LeetCode: https://meg.chai.ac.cn/leetcode-xxx/
  • UVa OJ: https://meg.chai.ac.cn/uvaoj-xxx/

Online Judge 模版与命令行

推荐使用 Visual Studio Code 并配置好对应的 c_cpp_properties.json 文件。

基本目录结构
1
2
3
4
5
.
├── data.in
├── data.out
├── main.cpp
└── main.py
C++ 文件初始状态(建议设置成 Snippet)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;
int main () {
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
    // Start Code Here
    fclose(stdin);
    fclose(stdout);
    return 0;
}
Linter & Formatter & Run (一般编辑器有对应插件)
1
2
3
4
5
6
7
8
9
# C++
clang-format -style=google -i main.cpp
cpplint --filter=-legal/copyright,-build/namespaces main.cpp
g++ -g -O0 main.cpp && ./a.out && cat data.out
 
# Python
autopep8 --in-place --aggressive --aggressive main.py
pylint --disable=C0103,C0114,C0116 main.py
python3 main.py < data.in

相关书籍中的题目整理

  • 算法竞赛入门经典(第二版)& 例题习题解答 :两本书中从第 3 章开始出现的习题和例题解答。

赞赏 赞(0)
订阅
提醒
guest
guest
0 评论
内嵌评论
查看所有评论
  • 0
  • 0
Copyright © 2020-2023 MEGChai.
  • 文章
    • 随笔
    • 笔记
    • 教程
  • 关于
# 生活 # # 心理 # # 编程 # # 音乐 # # 写作 #
Chai
95
文章
4
评论
58
喜欢
wpDiscuz