05 2022 档案

摘要:不使用 vector 的写法 点击查看代码 #include<iostream> #include<cmath> using namespace std; // 计算 n 有多少位 int dgt(int n) { int res = 0; while (n) { res ++; n /= 10; 阅读全文
posted @ 2022-05-25 09:40 wKingYu 阅读(18) 评论(0) 推荐(0) 编辑
摘要:类比完全背包 复杂度 O(n2) 总体复杂度 10002=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 1010, mod = 1e9 + 7; int n; 阅读全文
posted @ 2022-05-24 20:44 wKingYu 阅读(24) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n3) 总体复杂度 3003=2.7×107 点击查看代码 #include<iostream> using namespace std; const int N = 300 + 10; int n; int s[N]; int f[N 阅读全文
posted @ 2022-05-24 20:10 wKingYu 阅读(29) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(nml2) 总体复杂度 1000×1000×102=1×108 点击查看代码 #include<iostream> #include<cstring> using namespac 阅读全文
posted @ 2022-05-24 17:48 wKingYu 阅读(31) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n2) 总体复杂度 10002=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; char a[N], b[N]; in 阅读全文
posted @ 2022-05-24 17:07 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(nm) 总体复杂度 1000×1000=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; char a[N] 阅读全文
posted @ 2022-05-23 21:07 wKingYu 阅读(28) 评论(0) 推荐(0) 编辑
摘要:贪心 + 二分 复杂度 O(nlog(n)) 总体复杂度 1×105×log(1×105)1.66×106 点击查看代码 #include<iostream> using na 阅读全文
posted @ 2022-05-23 19:58 wKingYu 阅读(31) 评论(0) 推荐(0) 编辑
摘要:线性 dp 复杂度 O(n2) 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n; int a[N], f[N]; int main() { cin >> n; for (int i = 0 阅读全文
posted @ 2022-05-23 18:01 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑
摘要:使用一维数组优化 复杂度 n2 总体复杂度 5002=2.5×105 点击查看代码 #include<iostream> using namespace std; const int N = 510, INF = 1e9; int n; int a 阅读全文
posted @ 2022-05-20 18:28 wKingYu 阅读(14) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 110; int n, m; int v[N][N], w[N][N], s[N]; int f[N]; int main() { cin >> n >> m; for (int 阅读全文
posted @ 2022-05-20 17:28 wKingYu 阅读(11) 评论(0) 推荐(0) 编辑
摘要:n,v,s 都较小 朴素写法 时间复杂度 n×v×s 总体复杂度 1003=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 11 阅读全文
posted @ 2022-05-20 16:48 wKingYu 阅读(25) 评论(0) 推荐(0) 编辑
摘要:1. 朴素做法(会超时) 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N][N]; int main() { cin >> n >> m; for 阅读全文
posted @ 2022-05-16 14:28 wKingYu 阅读(23) 评论(0) 推荐(0) 编辑
摘要:1. 朴素做法(二维数组) 点击查看代码 #include<iostream> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N][N]; int main() { cin >> n >> m; fo 阅读全文
posted @ 2022-05-16 11:20 wKingYu 阅读(21) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> #include<unordered_set> using namespace std; const int N = 110; int n; int f[N]; int sg(int x) { if (f[x] 阅读全文
posted @ 2022-05-16 00:24 wKingYu 阅读(18) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> #include<unordered_set> using namespace std; const int N = 110, M = 1e4 + 10; int k, n; int s[N], f[M]; // 阅读全文
posted @ 2022-05-15 22:15 wKingYu 阅读(38) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; int main() { int n; cin >> n; int res = 0; for (int i = 1; i <= n; i ++) { int x; scanf("%d", &x); if ( 阅读全文
posted @ 2022-05-15 20:30 wKingYu 阅读(35) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; int main() { int n; cin >> n; int res = 0; while (n --) { int x; scanf("%d", &x); res ^= x; } if (res) 阅读全文
posted @ 2022-05-15 17:52 wKingYu 阅读(31) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; typedef long long LL; const int N = 20; int n, m; int p[N]; int main() { cin >> n >> m; for (int i = 0; 阅读全文
posted @ 2022-05-14 21:54 wKingYu 阅读(16) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; typedef long long LL; const int mod = 1e9 + 7; int qmi(int a, int k) { int res = 1; while (k) { if (k & 阅读全文
posted @ 2022-05-14 21:05 wKingYu 阅读(26) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<vector> using namespace std; const int N = 5e3 + 10; int primes[N], cnt, sum[N]; bool st[N]; void get_primes(int n) 阅读全文
posted @ 2022-05-14 17:13 wKingYu 阅读(26) 评论(0) 推荐(0) 编辑
摘要:复杂度 g(n) log(n) (来自 OI Wiki) 总体复杂度 20×105×log(105)×log(1018)=4×107 点击查看代码 #include<iostream> using 阅读全文
posted @ 2022-05-14 15:53 wKingYu 阅读(50) 评论(0) 推荐(0) 编辑
摘要:预处理 复杂度 O(nlog(n)) 总体复杂度 105×log(109)=3×106 点击查看代码 #include<iostream> using namespace std; typedef long long L 阅读全文
posted @ 2022-05-14 13:00 wKingYu 阅读(48) 评论(0) 推荐(0) 编辑
摘要:递推 复杂度 O(n2) 总体复杂度 20002=4×106 点击查看代码 #include<iostream> using namespace std; const int N = 2e3 + 10, mod = 1e9 + 7; int c[N 阅读全文
posted @ 2022-05-14 11:29 wKingYu 阅读(20) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n3) 总体复杂度 1003=1×106 点击查看代码 #include<iostream> using namespace std; const int N = 110; int n, a[N][N]; int gauss() { i 阅读全文
posted @ 2022-05-12 17:53 wKingYu 阅读(45) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n3) 总体复杂度 1003=1×106 点击查看代码 #include<iostream> #include<cmath> using namespace std; const int N = 110; const double ep 阅读全文
posted @ 2022-05-12 17:26 wKingYu 阅读(29) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; typedef long long LL; LL exgcd(LL a, LL b, LL & x, LL & y) { if (!b) { x = 1, y = 0; return a; } LL d = 阅读全文
posted @ 2022-05-11 23:38 wKingYu 阅读(35) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(log(n)) 总体复杂度 105×log(2×109)4×106 点击查看代码 #include<iostream> using namespace std; typedef long lon 阅读全文
posted @ 2022-05-11 20:22 wKingYu 阅读(41) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(log(n)) 总体复杂度 105×log(2×109)4×106 点击查看代码 #include<iostream> using namespace std; int exgcd(int 阅读全文
posted @ 2022-05-09 23:41 wKingYu 阅读(34) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(log(k)) (k 是指数) 总体复杂度 105×log(2×109)4×106 点击查看代码 #include<iostream> using namespace std; typedef 阅读全文
posted @ 2022-05-09 21:38 wKingYu 阅读(28) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(log(k)) (k 是指数) 总体复杂度 105×log(2×109)4×106 点击查看代码 #include<iostream> using namespace std; typedef 阅读全文
posted @ 2022-05-09 13:26 wKingYu 阅读(30) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n) 总体复杂度 106 点击查看代码 #include<iostream> using namespace std; const int N = 1e6 + 10; typedef long long LL; int primes[N], cnt; int eul 阅读全文
posted @ 2022-05-09 11:53 wKingYu 阅读(36) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n) 总体复杂度 100×2×1094.5×106 点击查看代码 #include<iostream> using namespace std; void solve(in 阅读全文
posted @ 2022-05-09 09:37 wKingYu 阅读(28) 评论(0) 推荐(0) 编辑
摘要:欧几里得算法(辗转相除法) 复杂度 O(log(n)) 总体复杂度 105×log(2×109)4×106 点击查看代码 #include<iostream> using namespace std; in 阅读全文
posted @ 2022-05-08 22:14 wKingYu 阅读(32) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n) 总体复杂度 100×2×1094.5×106 点击查看代码 #include<iostream> #include<unordered_map> using name 阅读全文
posted @ 2022-05-08 21:42 wKingYu 阅读(55) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n) 总体复杂度 100×2×1094.5×106 点击查看代码 #include<iostream> #include<unordered_map> using name 阅读全文
posted @ 2022-05-08 21:09 wKingYu 阅读(103) 评论(0) 推荐(0) 编辑
摘要:试除法 复杂度 O(n) 总体复杂度 100×2314.6×106 点击查看代码 #include<iostream> #include<vector> #include<algorithm> usi 阅读全文
posted @ 2022-05-08 19:58 wKingYu 阅读(19) 评论(0) 推荐(0) 编辑
摘要:埃氏筛法 复杂度 O(nlog(log(n))) 总体复杂度 106×log(log(106))5×106 点击查看代码 #include<iostream> using namespace std; const in 阅读全文
posted @ 2022-05-08 17:34 wKingYu 阅读(37) 评论(0) 推荐(0) 编辑
摘要:试除法 复杂度 O(log(n)) ~ O(n) 100×log(231)=31×100×log(2)=3100 < 总体复杂度 \(< 100 \times \sqrt{2^{31}} \approx 4 阅读全文
posted @ 2022-05-08 16:11 wKingYu 阅读(36) 评论(0) 推荐(0) 编辑
摘要:试除法 复杂度 O(n) 总体复杂度 100×2314.6×106 点击查看代码 #include<iostream> using namespace std; bool is_prime(int n 阅读全文
posted @ 2022-05-07 23:48 wKingYu 阅读(30) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 510, M = 1e5 + 10; int n1, n2, m; int h[N], e[M], ne[M], idx; bool st[N 阅读全文
posted @ 2022-05-07 23:25 wKingYu 阅读(24) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 1e5 + 10, M = 2 * N; int n, m; int h[N], e[M], ne[M], idx; int color[N] 阅读全文
posted @ 2022-05-07 21:37 wKingYu 阅读(19) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(mlog(m)) 点击查看代码 #include<iostream> #include<algorithm> using namespace std; const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f; int n, m; 阅读全文
posted @ 2022-05-07 15:23 wKingYu 阅读(26) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 510, INF = 0x3f3f3f3f; int n, m; int g[N][N]; int dist[N]; bool st[N]; 阅读全文
posted @ 2022-05-07 14:35 wKingYu 阅读(42) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n3) 点击查看代码 #include<iostream> using namespace std; const int N = 210, INF = 1e9; int n, m, k; int d[N][N]; void floyd() { for (int k = 1; 阅读全文
posted @ 2022-05-07 13:13 wKingYu 阅读(29) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; const int N = 1e5 + 10; int n, m; int h[N], e[N], ne[N], w[N], idx; i 阅读全文
posted @ 2022-05-07 11:07 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; const int N = 1e5 + 10; int n, m; int h[N], e[N], ne[N], w[N], idx; i 阅读全文
posted @ 2022-05-07 10:28 wKingYu 阅读(39) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 510, M = 1e5 + 10; int n, m, k; int dist[N], last[N]; struct Edge { int 阅读全文
posted @ 2022-05-06 22:24 wKingYu 阅读(20) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(mlog(n)) 点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; typedef pair<int, int> PII; const int N = 1e6 + 1 阅读全文
posted @ 2022-05-06 10:58 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑
摘要:复杂度 O(n2) 点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 510; int n, m; int g[N][N], dist[N]; bool st[N]; int d 阅读全文
posted @ 2022-05-06 09:40 wKingYu 阅读(20) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; const int N = 1e5 + 10; int n, m; int h[N], e[N], ne[N], idx; int d[N 阅读全文
posted @ 2022-05-06 08:55 wKingYu 阅读(32) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; const int N = 1e5 + 10; int n, m; int h[N], e[N], ne[N], idx; int d[N 阅读全文
posted @ 2022-05-05 23:37 wKingYu 阅读(32) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 1e5 + 10, M = 2 * N; int n, ans = N; int h[N], e[M], ne[M], idx; bool s 阅读全文
posted @ 2022-05-05 22:57 wKingYu 阅读(42) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> #include<queue> #include<unordered_map> using namespace std; int bfs(string start) { string end = "12345678x"; queue<string> 阅读全文
posted @ 2022-05-05 15:06 wKingYu 阅读(26) 评论(0) 推荐(1) 编辑
摘要:BFS 使用STL中的queue 点击查看代码 #include<iostream> #include<cstring> #include<queue> using namespace std; typedef pair<int, int> PII; const int N = 100 + 10; 阅读全文
posted @ 2022-05-05 00:19 wKingYu 阅读(51) 评论(0) 推荐(1) 编辑
摘要:DFS 按行枚举 时间复杂度 O(n!) 点击查看代码 #include<iostream> using namespace std; const int N = 20; int n; char g[N][N]; bool col[N], dg[N], udg[N]; void dfs(in 阅读全文
posted @ 2022-05-04 23:04 wKingYu 阅读(35) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 10; int n, path[N]; bool st[N]; void dfs(int u) { if (u > n) { for (int i = 1; i <= n; i 阅读全文
posted @ 2022-05-04 21:24 wKingYu 阅读(21) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; typedef unsigned long long ULL; const int N = 1e5 + 10; const int P = 131; int h[N], p[N]; char str[N]; 阅读全文
posted @ 2022-05-03 22:16 wKingYu 阅读(38) 评论(0) 推荐(0) 编辑
摘要:拉链法 点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 1e5 + 3; int h[N], e[N], ne[N], idx; void insert(int x) { int k = ( 阅读全文
posted @ 2022-05-03 19:35 wKingYu 阅读(29) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int h[N], sz, m; int ph[N], hp[N]; void heap_swap(int a, int b) { swap(ph[hp[a] 阅读全文
posted @ 2022-05-03 17:44 wKingYu 阅读(33) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int h[N], sz; void down(int u) { int t = u; if (2 * u <= sz && h[2 * u] < h[t]) 阅读全文
posted @ 2022-05-03 15:50 wKingYu 阅读(16) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int p[N], sz[N]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x 阅读全文
posted @ 2022-05-02 21:28 wKingYu 阅读(16) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int p[N]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x]; } in 阅读全文
posted @ 2022-05-02 20:54 wKingYu 阅读(22) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; const int M = 5e6 + 10; int son[M][2], idx; int a[N]; void insert(int x) { int 阅读全文
posted @ 2022-05-02 20:04 wKingYu 阅读(24) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 6e5 + 10; int son[N][26], cnt[N], idx; char str[N]; void insert(char str[]) { int p = 0; 阅读全文
posted @ 2022-05-02 17:15 wKingYu 阅读(27) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; const int M = 1e6 + 10; int ne[N]; int main() { int n, m; char p[N], s[M]; cin 阅读全文
posted @ 2022-05-02 16:35 wKingYu 阅读(18) 评论(0) 推荐(0) 编辑

欢迎阅读『2022 年 5月 随笔档案』
点击右上角即可分享
微信分享提示