🔖 exceltools

Usage

  • 启用 VBA (*.xlsm 文件中有效)

    • 在 Excel 中:文件 --> 选项 --> 自定义功能区 勾选 开发工具
    excel-enable-vba.png
  • 启用 Microsoft VBScript Regular Expressions5.5 模块

    • 打开 Visual Basic 编辑器:开发工具 --> Visual Basic
    • Visual Basic 编辑器中打开:工具 --> 引用
    • 在弹出的对话框中勾选 Microsoft VBScript Regular Expressions 5.5
    excel-enable-vba-regex.png

🔖 webfrontendcss

选择器优先级

  • CSS 选择器类型的优先级: 内联样式 > ID 选择器 > 类选择器 > 标签选择器

    具体计算规则如下,其中 (a,b,c,d) 将作为向量比较大小,即左侧的数值有绝对优先权

    A specificity is determined by plugging numbers into

🔖 reactreact hooks

useDeepCompareCallback

Deep compare version of React.useCallback

useDeepCompareCallback.ts  | 24 lines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { isEqual } from '@guanghechen/equal'
import type React from 'react'
import { useCallback, useRef } from 'react'
/**
* Deep compare version of React.useCallback
* @param fn
* @param deps
*/
export function useDeepCompareCallback<T extends (...args: any[]) => any>(
fn: T,
deps: React.DependencyList,
): T {
const signal = useRef<number>(0)
const prevDeps = useRef<React.DependencyList>(deps)
if (!isEqual(prevDeps.current, deps)) {
signal.current += 1
}
prevDeps.current = deps
// eslint-disable-next-line react-hooks/exhaustive-deps
return useCallback(fn, [signal.current])
}

useDeepCompareEffect

Deep compare version of React.useEffect

useDeepCompareEffect.ts  | 21 lines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { isEqual } from '@guanghechen/equal'
import type React from 'react'
import { useEffect, useRef } from 'react'
/**
* Deep compare version of React.useEffect
* @param fn
* @param deps
*/
export function useDeepCompareEffect(fn: React.EffectCallback, deps: React.DependencyList): void {
const signal = useRef<number>(0)
const prevDeps = useRef<React.DependencyList>(deps)
if (!isEqual(prevDeps.current, deps)) {
signal.current += 1
}
prevDeps.current = deps
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(fn, [signal.current])
}

useDeepCompareMemo

Deep compare version of React.useMemo

useDeepCompareMemo.ts  | 21 lines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { isEqual } from '@guanghechen/equal'
import type React from 'react'
import { useMemo, useRef } from 'react'
/**
* Deep compare version of React.useMemo
* @param fn
* @param deps
*/
export function useDeepCompareMemo<T>(fn: () => T, deps: React.DependencyList): T {
const signal = useRef<number>(0)
const prevDeps = useRef<React.DependencyList>(deps)
if (!isEqual(prevDeps.current, deps)) {
signal.current += 1
}
prevDeps.current = deps
// eslint-disable-next-line react-hooks/exhaustive-deps
return useMemo(fn, [signal.current])
}

useInterval

Execute callback interval in react function components.

userInterval.ts  | 25 lines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { useEffect, useRef } from 'react'
type Callback = () => void
/**
* Execute callback interval in react function components.
* @param callback
* @param delay
*/
export function useInterval(callback: Callback, delay: number): void {
const callbackRef = useRef<Callback>(callback)
useEffect(() => {
callbackRef.current = callback
}, [callback])
useEffect(() => {
const tick: Callback = () => {
if (callbackRef.current === undefined) return
callbackRef.current()
}
const id = setInterval(tick, delay)
return () => clearInterval(id)
}, [delay])
}

usePreviousState

记录上一个状态。

利用更新 ref.current 的值不会触发组件更新的特性,在 usePreviousState 中总是返回旧的值,尽管在 userPreviousStateuseEffect 中更新了新值,但并不触发更新。

usePreviousState.ts  | 14 lines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { useEffect, useRef } from 'react'
/**
* Use previous state.
* @param value
* @returns
*/
export function usePreviousState<T = unknown>(value: T): T {
const ref = useRef<T>(value)
useEffect(() => {
ref.current = value
}, [value])
return ref.current
}

useReactiveRef

useReactiveRef.ts  | 15 lines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import type React from 'react'
import { useEffect, useRef } from 'react'
/**
* Create a reactive ref which will follow the changes of the given data.
* @param data
* @returns
*/
export function useReactiveRef<T>(data: T): React.MutableRefObject<T> {
const ref = useRef(data)
useEffect(() => {
ref.current = data
}, [data])
return ref
}

🔖 组合数学组合游戏SG 定理

NP 状态描述

  • 无法进行任何移动的局面为 P-position
  • 可以移动到 P-position 的局面为 N-position
  • 任意移动都到达 N-position 的局面为 P-position

Nim 游戏

Nim 游戏是组合游戏中的经典游戏,描述如下:有 n 堆石子,第 i 堆有

🔖 acm算法图论网络流二分图解题报告专题训练

Prepare

由于网络流问题难点在于建模,网络流算法基本都是围绕增广路,且相关的文章网上已经有许多了,故此下文中将给出会多次使用到的模板代码,而且其具体的算法略去。

  • ISAP

    isap.hpp  | 107 lines.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    #include <cstring>
    #include <queue>
    #include <vector>
    namespace ISAP {
    static const int MAXN = 10000 + 10;
    static const int INF = 0x3f3f3f3f;
    struct Edge {
    int from, to, cap, flow;
    Edge(int from = 0, int to = 0, int cap = 0, int flow = 0)
    : from(from), to(to), cap(cap), flow(flow) {
    }
    };
    int s, t, n;
    int cnt[MAXN];
    int cur[MAXN];
    int path[MAXN];
    int dist[MAXN];
    std::vector<Edge> edges;
    std::vector<int> G[MAXN];
    std::queue<int> Q;
    void addedge(int from, int to, int cap) {
    int siz = edges.size();
    edges.push_back(Edge(from, to, cap, 0));
    edges.push_back(Edge(to, from, 0, 0));
    G[from].push_back(siz);
    G[to].push_back(siz + 1);
    }
    void BFS() {
    memset(dist, -1, sizeof dist);
    Q.push(t);
    dist[t] = 0;
    while (!Q.empty()) {
    int o = Q.front();
    Q.pop();
    for (int i = 0; i < G[o].size(); ++i) {
    Edge& e = edges[G[o][i]];
    if (dist[e.to] == -1 && e.cap == 0) {
    dist[e.to] = dist[o] + 1;
    Q.push(e.to);
    }
    }
    }
    }
    int augment() {
    int mif = INF;
    for (int o = t; o != s;) {
    Edge& e = edges[path[o]];
    mif = std::min(mif, e.cap - e.flow);
    o = e.from;
    }
    for (int o = t; o != s;) {
    edges[path[o]].flow += mif;
    edges[path[o] ^ 1].flow -= mif;
    o = edges[path[o]].from;
    }
    return mif;
    }
    int maxflow() {
    BFS();
    memset(cur, 0, sizeof cur);
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; ++i)
    if (dist[i] < n) ++cnt[dist[i]];
    int ans = 0;
    for (int o = s; dist[o] < n;) {
    if (o == t) ans += augment(), o = s;
    bool ok = false;
    for (int i = cur[o]; i < G[o].size(); ++i) {
    Edge& e = edges[G[o][i]];
    if (e.cap > e.flow && dist[o] == dist[e.to] + 1) {
    ok = true;
    cur[o] = i;
    path[e.to] = G[o][i];
    o = e.to;
    break;
    }
    }
    if (!ok) {
    int d = n - 1;
    for (int i = 0; i < G[o].size(); ++i) {
    Edge& e = edges[G[o][i]];
    if (e.cap > e.flow) d = std::min(d, dist[e.to]);
    }
    if (--cnt[dist[o]] == 0) break;
    ++cnt[dist[o] = d + 1];
    cur[o] = 0;
    if (o != s) o = edges[path[o]].from;
    }
    }
    return ans;
    }
    void solve();
    void solve(int);
    void solve(int, int);
    void solve(int, int, int);
    }; // namespace ISAP

🔖 算法图论网络流最大权闭合图

Terms

对于有向图 G=(V,E),其中 VG 的点集,EG 的边集。

  • 割集: 一个 st[S,T]V 的一种划分,使得 sStT

  • 最小割: 一个 st 割的容量是 c(S,T)=(μ,ν)(S×T)Ec(μ,ν)

🔖 acm训练赛数据结构解题报告

1004 Differencia

题目描述

有两个序列:

  • {a1,a2,,an}
  • {b1,b2,,bn}

有两种操作:

  • +lrx: 将所有的
© 2017-2025 光和尘有花满渚、有酒盈瓯