ARTS 第 拾一 期

Algorithm

题目:
https://leetcode.cn/problems/maximum-height-of-a-triangle/description/

题解:
分别以红球、蓝球作为第一行的颜色,逐行模拟摆放(奇数行用一种颜色,偶数行用另一种颜色),取两者高度的较大值,时间复杂度:O(√(red+blue))

class Solution {
public:
    int maxHeightOfTriangle(int red, int blue) {
        return max(height(red, blue), height(blue, red));
    }
private:
    // a 为奇数行的颜色球数,b 为偶数行的颜色球数
    int height(int a, int b) {
        int h = 0;
        while (true) {
            int need = h + 1;
            int &c = (need % 2) ? a : b;
            if (c < need) break;
            c -= need;
            h++;
        }
        return h;
    }
};

Review

https://www.octomind.dev/blog/why-we-no-longer-use-langchain-for-building-our-ai-agents

主要介绍了这个团队为啥不再使用 langchain 来开发 Ai 代理,langchain 为了屏蔽细节,用了很多抽象,但是这也间接失去了简单性和灵活性。

Tip

  1. bazel //… 还是少用,一方面会编译很多可能不用的 target, 影响编译效率,另一方面,会导致不少坑
    2.判断奇偶,除了常用方法,还可以通过和数字 1 按位与来判断
    3.动态库A依赖于静态库 B,B 的符号不会自动导出到 A 中,可以通过 –whole-archive -lB–no-whole-archive 在链接时导出符号到 A 中
    https://stackoverflow.com/questions/805555/ld-linker-question-the-whole-archive-option

Share

几个调度框架可以学习参考一下,有趣的是都是基于 DAG(有向无环图):

https://github.com/ChunelFeng/CGraph
CGraph中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过GPipeline(流水线)底层调度,实现了依赖元素依次顺序执行、非依赖元素并发执行的调度功能。

https://github.com/taskflow/taskflow
A General-purpose Task-parallel Programming System using Modern C++

请我喝杯咖啡