颜林林的“左耳听风ARTS”打卡记录

ARTS第四十八周(2020年8月17日~23日)

2020-08-17

Algorithm

LeetCode题库

编号 难度 题目 我的解答 执行用时 内存消耗 用时排名 内存排名 查看结果
312 困难 戳气球 200822-1.cpp 76 ms 9 MB 6.15% 9.09% 查看结果
313 中等 超级丑数 200822-1.cpp 200 ms 9.6 MB 37.88% 31.00% 查看结果

Review

1. 依据流程构建工具

参考:Build tools around workflows, not workflows around tools

这是一篇关于日常工作效率相关的文章,作者介绍了自己日常所用的工具,这些工具都比较轻量级,没有过多的不必要特性,却能比较有效地帮助作者达成其相应目的。我们构建各类工具时,应该围绕自己的流程目的去进行,而不是舍本逐末地为了工具去构建流程。

Tip

1. 在bash中处理日期计算

参考:How to add days to date and get new date on Linux

1
2
3
4
5
date --date='2 days ago'      # 两天前
date --date='4 months 2 day'  # 四个月零两天后

date -d "2020-08-22 + 20 days"  # 特定日期之后多少天
date -d "2020-08-22 - 20 days"  # 特定日期之前多少天

Share

1. C++命令行解析库

参考:https://github.com/p-ranav/structopt

C++类库,提供了一个易用的命令行解析功能

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <structopt/app.hpp>

struct FileOptions {
    // Positional arguments
    // ./main <input_file> <output_file>
    std::string input_file;
    std::string output_file;
};
STRUCTOPT(FileOptions, input_file, output_file);

int main(int argc, char *argv[]) {
    try {
        auto options = structopt::app("my_app").parse<FileOptions>(argc, argv);

        // Print parsed arguments:
        std::cout << "\nInput file  : " << options.input_file << "\n";
        std::cout << "Output file : " << options.output_file << "\n";

    } catch (structopt::exception& e) {
        std::cout << e.what() << "\n";
        std::cout << e.help();
    }
}

2. C++ Weekly视频:constexpr map实现

参考:YouTube: C++ Weekly - Ep 233 - std::map vs constexpr map (huge perf difference!)

将查找逻辑在编译期展开成为代码,通过gcc优化,能够比std::map快11倍。