摘要:
1.Floyd写法: #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 26; int n, m; bool d[N][N]; bool st[N]; int 阅读全文
摘要:
根号分治模板题 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <cmath> #define RED "\033[0;32;31m" #define NONE "\033 阅读全文
摘要:
简单的树形DP #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #define For(i, j, n) for (int i = j; i <= n; ++i) using namespa 阅读全文
摘要:
这道题的精髓在于DP公式的推理 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> using namespace std; const int N = 1005, mod = 10000000 阅读全文
摘要:
这道题的数据范围比较突出: 1<=N<=1e9 先写一个O(N)算法: #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #define int long long using namespa 阅读全文
摘要:
算出两个数字的坐标,然后返回曼哈顿距离。 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <cmath> using namespace std; int w, m, n, 阅读全文
摘要:
这道题是把拓扑排序和迪杰斯特拉交叉进行。 #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <queue> #include <vector> using namespace 阅读全文
摘要:
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];//注意是向上取整,因为向下 阅读全文
摘要:
因为相邻两个数字交换,每次只能减少一个逆序对数量,所以这道题最终的交换次数就等于原序列当中逆序对的数量。 但是因为每个数字的交换代价会随着交换次数而增加,所以虽然我们知道Σ数字交换次数 = 逆序对数量,我们也不能按照传统的逆序对数量统计方式直接计算,这样子会导致我们只知道最终的交换次数,但不知道每个 阅读全文
摘要:
这道题采用贪心,两只蚂蚁相互传染后再同时掉头走,相当于穿过了对方,若无其事地走,并不会影响最后感冒的传播结果。 #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <queue> u 阅读全文