What are practical uses for STL's 'partial_sum'?

前端 未结 11 1754
耶瑟儿~
耶瑟儿~ 2021-02-04 03:47

What/where are the practical uses of the partial_sum algorithm in STL?

What are some other interesting/non-trivial examples or use-cases?

11条回答
  •  春和景丽
    2021-02-04 04:52

    Last time I (would have) used it is when converting a discrete probability distribution (an array of p(X = k)) into a cumulative distribution (an array of p(X <= k)). To select once from the distribution, you can pick a number from [0-1) randomly, then binary search into the cumulative distribution.

    That code wasn't in C++, though, so I did the partial sum myself.

提交回复
热议问题