算法技巧-随机化
文章平均质量分 93
介绍随机算法和随机化的应用
memcpy0
希望探索文理结合的自由之路。
展开
-
LeetCode 497. Random Point in Non-overlapping Rectangles【数学/前缀和/二分/随机化/蓄水池抽样】
You are given an array of non-overlapping axis-aligned rectangles rects where rects[i] = [ai, bi, xi, yi] indicates that (ai, bi) is the bottom-left corner point of the ith rectangle and (xi, yi) is the top-right corner point of the ith rectangle. Design a原创 2021-09-04 13:36:30 · 186 阅读 · 0 评论 -
LeetCode 398. Random Pick Index【蓄水池抽样/哈希表/随机化】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,这个截止期限可能是永远。这一系列刷题文章中,不仅会讲解多种解题思路及其优化,还将用多种编程语言实现题解,涉及到通用解法时更会归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还将建立相关的仓库:https://github.com/memcpy0/LeetCode-Conquest。.原创 2021-09-04 00:24:46 · 177 阅读 · 0 评论 -
LeetCode 528. Random Pick with Weight【数学/前缀和/随机化/二分】中等
You are given an array of positive integers w where w[i] describes the weight of ith index (0-indexed).We need to call the function pickIndex() which randomly returns an integer in the range [0, w.length - 1]. pickIndex() should return原创 2021-08-31 17:05:47 · 237 阅读 · 0 评论 -
LeetCode C++ 470. Implement Rand10() Using Rand7()【Math/Random】中等
Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn’t call any other API. Please do no原创 2020-11-13 00:13:36 · 135 阅读 · 0 评论 -
【算法学习】随机化算法 随机数生成器和mt19937
文章目录1. 伪随机数2. 模运算3. 线性同余数生成器1. 伪随机数Treap和随机快速排序等需要用到随机数,我们也要有一种方法来生成它。不过,真正的随机性在计算机中是稀缺的,如果想要在实际应用中使用生成的随机数,太慢是不行的。一般来说,产生伪随机数 pseudorandom number 就足够了。伪随机数是指看上去像是随机的数。随机数有很多的统计性质,而伪随机数满足其中的大部分。然而,生成伪随机数也不是那么容易的。以抛一枚硬币为例,随机生成 0 正面或者 1 负面。一种做法是借用系统时钟,将时原创 2020-08-14 16:24:52 · 1157 阅读 · 0 评论