摘要: 基于比较的排序(复杂度下界nlogn) 冒泡排序 时间复杂度 最坏O(n2) 平均O(n2) 最好O(n) 空间复杂度 O(1) 稳定 void bubbleSort(int *a, int n) { for (int i = n - 1, t; i; i = t) { t = i; for (in 阅读全文
posted @ 2020-07-29 14:53 watchphone 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 埃拉托斯特尼筛法(The sieve of Eratosthenes) https://www.luogu.com.cn/problem/P3912 //只算出来了素数的个数 #include <cstdio> const int N = 100000010; bool isNotPrime[N]; 阅读全文
posted @ 2020-02-20 17:13 watchphone 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 模型:n个0和n个1组成一个2n位的2进制数,要求从左到右扫描时, 1的累计数始终都小于等于0的累计数 ,求满足条件的数有多少? 证明:在2n位上填入n个0的方案数为$C_{2n}^{n}$。而从$C_{2n}^{n}$中减去不符合要求的方案数即为所求答案。在从左往右扫时,必然会在某一个奇数位$2p 阅读全文
posted @ 2020-02-16 21:21 watchphone 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 一维树状数组常用的三种方式 阅读全文
posted @ 2020-02-14 21:27 watchphone 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2020-02-12 00:02 watchphone 阅读(142) 评论(0) 推荐(0) 编辑