Skip to content

Commit ac7417a

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 3b501b0 + 0a0a333 commit ac7417a

File tree

10 files changed

+47
-20
lines changed

10 files changed

+47
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,6 @@ My GoLand `Live Templates` and `Postfix Completion` [settings](/misc/my_goland_t
425425

426426
[Elo rating system](https://en.wikipedia.org/wiki/Elo_rating_system#Theory)
427427

428-
### Keep Healthy
428+
### Stay Healthy
429429

430430
[Exercises!](https://musclewiki.org/)

copypasta/bits.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ https://oeis.org/A003459 绝对素数/可交换素数 Absolute primes (or permut
149149
https://en.wikipedia.org/wiki/Permutable_prime
150150
https://oeis.org/A007500 Primes whose reversal in base 10 is also prime
151151
https://oeis.org/A006995 二进制回文数
152+
https://oeis.org/A007632 既是二进制回文数又是十进制回文数
152153
153154
https://oeis.org/A090994 Number of meaningful differential operations of the n-th order on the space R^9
154155
a(k+5) = a(k+4) + 4*a(k+3) - 3*a(k+2) - 3*a(k+1) + a(k)

copypasta/dp.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ func dpCollections() {
398398
// LC1312 https://leetcode-cn.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/ https://www.luogu.com.cn/problem/P1435
399399
// 其中一个改为子串 https://codeforces.com/problemset/problem/163/A
400400
// https://codeforces.com/problemset/problem/1446/B
401+
// 多个排列的 LCS(转化成 DAG 最长路)https://codeforces.com/problemset/problem/463/D
401402
// 转换【巧妙】https://codeforces.com/problemset/problem/1114/D
402403
// 20多校第二场 https://acm.hdu.edu.cn/showproblem.php?pid=6774
403404
// 与 KMP 结合 https://codeforces.com/problemset/problem/346/B
@@ -478,6 +479,7 @@ func dpCollections() {
478479
}
479480

480481
// 最长回文子序列 (LPS)
482+
// 即 LCS(s, reverse(s))
481483
// LC516 https://leetcode-cn.com/problems/longest-palindromic-subsequence/
482484
// LC1216/双周赛10D https://leetcode-cn.com/contest/biweekly-contest-10/problems/valid-palindrome-iii/
483485
longestPalindromeSubsequence := func(s string) int {
@@ -1691,7 +1693,7 @@ func dpCollections() {
16911693
//}
16921694
ans = (ans%mod + mod) % mod
16931695

1694-
// TIPS: 对于需要判断/禁止前导零的情况,可以加一个额外的维度 valid,表示已经填入了数字(没有前导零的合法状态),最后 p>=n 的时候可以根据情况返回 1 或者 0
1696+
// TIPS: 对于需要判断/禁止前导零的情况,可以加一个额外的维度 fill,表示已经填入了数字(没有前导零的合法状态),最后 p>=n 的时候可以根据情况返回 1 或者 0
16951697
// 例如 https://codeforces.com/contest/855/submission/125651587
16961698
// 以下代码以 https://www.luogu.com.cn/problem/P2657 为例
16971699
calc = func(s string) int64 {
@@ -1701,12 +1703,12 @@ func dpCollections() {
17011703
dp[i][j] = -1
17021704
}
17031705
}
1704-
var f func(p, pre int, limitUp, valid bool) int64
1705-
f = func(p, pre int, limitUp, valid bool) (res int64) {
1706+
var f func(p, pre int, limitUp, fill bool) int64
1707+
f = func(p, pre int, limitUp, fill bool) (res int64) {
17061708
if p == len(s) {
17071709
return 1
17081710
}
1709-
if !limitUp && valid { // 注意这里的判断
1711+
if !limitUp && fill { // 注意这里的判断
17101712
dv := &dp[p][pre]
17111713
if *dv >= 0 {
17121714
return *dv
@@ -1718,8 +1720,8 @@ func dpCollections() {
17181720
up = int(s[p] & 15)
17191721
}
17201722
for d := 0; d <= up; d++ {
1721-
if !valid || abs(d-pre) > 1 {
1722-
res += f(p+1, d, limitUp && d == up, valid || d > 0)
1723+
if !fill || abs(d-pre) > 1 {
1724+
res += f(p+1, d, limitUp && d == up, fill || d > 0)
17231725
}
17241726
}
17251727
return
@@ -1739,14 +1741,14 @@ func dpCollections() {
17391741
}
17401742
}
17411743
var f func(int, uint16, bool, bool) pair
1742-
f = func(p int, mask uint16, limitUp, valid bool) (res pair) {
1744+
f = func(p int, mask uint16, limitUp, fill bool) (res pair) {
17431745
if p == n {
1744-
if !valid {
1746+
if !fill {
17451747
return
17461748
}
17471749
return pair{1, 0}
17481750
}
1749-
if !limitUp && valid {
1751+
if !limitUp && fill {
17501752
dv := &dp[p][mask]
17511753
if dv.cnt >= 0 {
17521754
return *dv
@@ -1759,11 +1761,11 @@ func dpCollections() {
17591761
}
17601762
for d := 0; d <= up; d++ {
17611763
tmp := mask
1762-
if valid || d > 0 {
1764+
if fill || d > 0 {
17631765
tmp |= 1 << d
17641766
}
17651767
if bits.OnesCount16(tmp) <= k {
1766-
pr := f(p+1, tmp, limitUp && d == up, valid || d > 0)
1768+
pr := f(p+1, tmp, limitUp && d == up, fill || d > 0)
17671769
res.cnt = (res.cnt + pr.cnt) % mod
17681770
res.sum = (res.sum + int64(math.Pow10(n-1-p))%mod*pr.cnt%mod*int64(d) + pr.sum) % mod
17691771
}
@@ -1972,6 +1974,7 @@ func dpCollections() {
19721974
todo 题单 https://ac.nowcoder.com/acm/problem/collection/807
19731975
题单 https://ac.nowcoder.com/acm/problem/collection/809
19741976
https://codeforces.com/problemset/problem/982/C
1977+
https://codeforces.com/problemset/problem/743/D
19751978
https://codeforces.com/problemset/problem/1083/A
19761979
好题 https://codeforces.com/problemset/problem/1453/E
19771980
如何定义状态 https://codeforces.com/problemset/problem/461/B

copypasta/fenwick_tree.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func fenwickTree(n int) {
106106

107107
// 求逆序对的方法之一
108108
// 如果 a 范围较大则需要离散化(但这样还不如直接用归并排序)
109+
// 归并做法见 misc.go 中的 mergeCount
109110
// 扩展 https://codeforces.com/problemset/problem/362/C
110111
// 环形最小逆序对 https://www.luogu.com.cn/problem/solution/P2995
111112
// 扩展:某些位置上的数待定时的逆序对的期望值 https://codeforces.com/problemset/problem/1096/F

copypasta/geometry.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ func (o circle) tangents2(b circle) (ls []lineF, hasInf bool) {
601601
// 详见《计算几何:算法与应用(第 3 版)》第 4.7 节
602602
// https://en.wikipedia.org/wiki/Smallest-circle_problem
603603
// https://oi-wiki.org/geometry/random-incremental/
604-
// 模板题 https://www.luogu.com.cn/problem/P1742 https://www.acwing.com/problem/content/3031/ https://www.luogu.com.cn/problem/P2533
604+
// 模板题 https://www.luogu.com.cn/problem/P1742 https://www.acwing.com/problem/content/3031/ https://www.luogu.com.cn/problem/P2533 LC1924 https://leetcode-cn.com/problems/erect-the-fence-ii/
605605
// 椭圆(坐标系旋转缩一下) https://www.luogu.com.cn/problem/P4288 https://www.acwing.com/problem/content/2787/
606606
func smallestEnclosingDisc(ps []vecF) circleF {
607607
rand.Seed(time.Now().UnixNano())
@@ -831,7 +831,8 @@ func vec2Collection() {
831831
// 求上凸包就从最右边的点开始
832832
// https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/GrahamScan.java.html
833833
// NOTE: 坐标值范围不超过 M 的凸多边形的顶点数为 O(√M) 个
834-
// 模板题 https://www.luogu.com.cn/problem/P2742
834+
// 模板题 https://www.luogu.com.cn/problem/P2742 LC587 https://leetcode-cn.com/problems/erect-the-fence/
835+
// 构造 LCP15 https://leetcode-cn.com/problems/you-le-yuan-de-mi-gong/
835836
// 限制区间长度的区间最大均值问题 https://codeforces.com/edu/course/2/lesson/6/4/practice/contest/285069/problem/A
836837
// todo poj 2187 1113 1912 3608 2079 3246 3689
837838
convexHull := func(ps []vec) (q []vec) {

copypasta/math.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func numberTheoryCollection() {
151151
152152
TIPS: 一般 LCM 的题目都需要用 LCM=x*y/GCD 转换成研究 GCD 的性质
153153
154+
GCD(x,x+y) = GCD(x,y) https://codeforces.com/problemset/problem/1110/C
154155
GCD 与质因子 https://codeforces.com/problemset/problem/264/B
155156
数组中最小的 LCM(ai,aj) https://codeforces.com/problemset/problem/1154/G
156157
分拆与 LCM https://ac.nowcoder.com/acm/contest/5961/D https://ac.nowcoder.com/discuss/439005
@@ -794,7 +795,16 @@ func numberTheoryCollection() {
794795

795796
// 阶乘的质因数分解中 p 的幂次
796797
// https://cp-algorithms.com/algebra/factorial-divisors.html
797-
// https://codeforces.com/contest/1114/problem/C
798+
// https://codeforces.com/problemset/problem/633/B
799+
// https://codeforces.com/problemset/problem/1114/C
800+
// https://oeis.org/A027868 p=5 时为 n! 尾零的个数
801+
// https://oeis.org/A191610 Possible number of trailing zeros in n!
802+
// https://oeis.org/A000966 n! never ends in this many 0's
803+
// The simplest way to obtain this sequence is by constructing a power series
804+
// A(x) = Sum_{k >= 1} x^a(k) whose exponents give the terms of the sequence.
805+
// Define e(n) = (5^n-1)/4, f(n) = (1-x^(e(n)-1))/(1-x^e(n-1)), t(n) = x^(e(n)-6).
806+
// 相关题目 LC793 https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function/
807+
// 数学解法 https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function/solution/shu-xue-tui-dao-by-jriver/
798808
powerOfFactorialPrimeDivisor := func(n, p int64) (k int64) {
799809
for n > 0 {
800810
n /= p

copypasta/misc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,11 @@ func mapPos(a, b []int) []int {
416416
return ids
417417
}
418418

419-
// 逆序对
419+
// 归并排序与逆序对
420420
// LC 面试题 51 https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/
421-
// EXTRA: LC 327 https://leetcode-cn.com/problems/count-of-range-sum/
422-
// LC 493 https://leetcode-cn.com/problems/reverse-pairs/
421+
// EXTRA: LC315 https://leetcode-cn.com/problems/count-of-smaller-numbers-after-self/
422+
// LC327 https://leetcode-cn.com/problems/count-of-range-sum/
423+
// LC493 https://leetcode-cn.com/problems/reverse-pairs/
423424
// 一张关于归并排序的好图 https://www.cnblogs.com/chengxiao/p/6194356.html
424425
func mergeCount(a []int) int64 {
425426
n := len(a)

copypasta/monotone_stack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ NEERC05,UVa 1619 https://onlinejudge.org/index.php?option=com_onlinejudge&Item
2323
https://codeforces.com/problemset/problem/1313/C2
2424
https://codeforces.com/problemset/problem/1407/D
2525
结合线段树,或者巧妙地在单调栈中去维护最值 https://codeforces.com/problemset/problem/1483/C
26+
单调队列优化 LC375 猜数字大小 II https://leetcode-cn.com/problems/guess-number-higher-or-lower-ii/
2627
2728
LC42 接雨水 https://leetcode-cn.com/problems/trapping-rain-water/
2829
评注:接雨水有三种不同的解法(DP、单调栈和双指针),其中双指针是 DP 的空间优化写法
@@ -78,7 +79,7 @@ func monotoneStack(a []int) ([]int, []int) {
7879
}
7980

8081
// EXTRA: 求所有长为 i 的子区间的最小值的最大值
81-
// LC1950 https://leetcode-cn.com/problems/maximum-of-minimum-values-in-all-subarrays/
82+
// https://codeforces.com/problemset/problem/547/B LC1950 https://leetcode-cn.com/problems/maximum-of-minimum-values-in-all-subarrays/
8283
{
8384
ans := make([]int, n+1)
8485
for i := range ans {

copypasta/sort.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,12 @@ func sortCollections() {
369369
// https://codeforces.com/gym/101649 K
370370
// https://www.luogu.com.cn/problem/P1570
371371
// https://loj.ac/p/149
372-
// 连续子段的算数平均值 https://codeforces.com/edu/course/2/lesson/6/4/practice/contest/285069/problem/A https://codeforces.com/problemset/problem/1003/C https://www.luogu.com.cn/problem/P1404 https://www.acwing.com/problem/content/104/
372+
// 有长度限制的连续子段的(最大/最小)算数平均值
373+
// https://codeforces.com/edu/course/2/lesson/6/4/practice/contest/285069/problem/A
374+
// https://codeforces.com/problemset/problem/1003/C
375+
// https://www.luogu.com.cn/problem/P1404
376+
// https://www.acwing.com/problem/content/104/
377+
// LC644 https://leetcode-cn.com/problems/maximum-average-subarray-ii/
373378
// O(n) 做法见 04 年集训队周源论文《浅谈数形结合思想在信息学竞赛中的应用》(或紫书 p.243 例题 8-9,UVa 1451 https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=447&page=show_problem&problem=4197)
374379
// 与 0-1 背包结合,即最优比率背包 https://www.luogu.com.cn/problem/P4377 https://ac.nowcoder.com/acm/contest/2271/F
375380
// 与生成树结合,即最优比率生成树 https://www.luogu.com.cn/problem/P4951 http://poj.org/problem?id=2728

copypasta/strings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func stringCollection() {
196196
// https://oi-wiki.org/string/minimal-string/
197197
// 其他方法 https://codeforces.com/blog/entry/90035
198198
// 模板题 https://www.luogu.com.cn/problem/P1368 http://poj.org/problem?id=1509
199+
// https://codeforces.com/problemset/problem/496/B
199200
smallestRepresentation := func(s []byte) []byte {
200201
n := len(s)
201202
s = append(s, s...)
@@ -218,6 +219,9 @@ func stringCollection() {
218219
return s[i : i+n]
219220
}
220221

222+
// 子序列自动机
223+
// LC727 https://leetcode-cn.com/problems/minimum-window-subsequence/
224+
// LC792 https://leetcode-cn.com/problems/number-of-matching-subsequences/
221225
// LC2014/周赛259D https://leetcode-cn.com/problems/longest-subsequence-repeated-k-times/
222226
subsequenceAutomaton := func(s string) {
223227
// build nxt

0 commit comments

Comments
 (0)