上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 45 下一页
摘要: 简单的树形DP #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #define For(i, j, n) for (int i = j; i <= n; ++i) using namespa 阅读全文
posted @ 2023-12-10 02:17 Gold_stein 阅读(30) 评论(0) 推荐(0)
摘要: 这道题的精髓在于DP公式的推理 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> using namespace std; const int N = 1005, mod = 10000000 阅读全文
posted @ 2023-12-07 18:35 Gold_stein 阅读(42) 评论(0) 推荐(0)
摘要: 这道题的数据范围比较突出: 1<=N<=1e9 先写一个O(N)算法: #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #define int long long using namespa 阅读全文
posted @ 2023-12-06 22:14 Gold_stein 阅读(32) 评论(0) 推荐(0)
摘要: 算出两个数字的坐标,然后返回曼哈顿距离。 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <cmath> using namespace std; int w, m, n, 阅读全文
posted @ 2023-12-06 11:02 Gold_stein 阅读(18) 评论(0) 推荐(0)
摘要: 这道题是把拓扑排序和迪杰斯特拉交叉进行。 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <queue> #include <vector> using namespace 阅读全文
posted @ 2023-12-04 17:30 Gold_stein 阅读(10) 评论(0) 推荐(0)
摘要: 1.以i为基准,且不带选取中位数的写法 // 从小到大 void quick_sort(int q[], int l, int r) { if(l >= r) return; int i = l - 1, j = r + 1, x = q[l + r + 1 >> 1];//注意是向上取整,因为向下 阅读全文
posted @ 2023-11-29 11:20 Gold_stein 阅读(40) 评论(0) 推荐(0)
摘要: 因为相邻两个数字交换,每次只能减少一个逆序对数量,所以这道题最终的交换次数就等于原序列当中逆序对的数量。 但是因为每个数字的交换代价会随着交换次数而增加,所以虽然我们知道Σ数字交换次数 = 逆序对数量,我们也不能按照传统的逆序对数量统计方式直接计算,这样子会导致我们只知道最终的交换次数,但不知道每个 阅读全文
posted @ 2023-11-20 23:24 Gold_stein 阅读(14) 评论(0) 推荐(0)
摘要: 这道题采用贪心,两只蚂蚁相互传染后再同时掉头走,相当于穿过了对方,若无其事地走,并不会影响最后感冒的传播结果。 #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <queue> u 阅读全文
posted @ 2023-11-19 17:43 Gold_stein 阅读(31) 评论(0) 推荐(0)
摘要: 这道题既可以用图论多次求单源最短路暴力来做,也可以用正解:求树的直径来做。 #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <iostream> #include <vector> using namespac 阅读全文
posted @ 2023-11-19 17:42 Gold_stein 阅读(9) 评论(0) 推荐(0)
摘要: 经典的记忆化搜索,一开始因为最后的答案忘记加取模卡了半天,真是愚蠢至极。 #include <iostream> #include <algorithm> #include <stdio.h> #include <stdlib.h> #include <cstring> using namespac 阅读全文
posted @ 2023-11-19 17:40 Gold_stein 阅读(17) 评论(0) 推荐(0)
上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 45 下一页