摘要: 水 //埃氏筛 void Era(int qwq){ for(int i=2;i<=qwq;i++){ if(vis[i])continue;//是合数就不执行 for(int j=i*2;j<=qwq;j+=i) vis[j]=true;//j=i的倍数,每次加i,即为i的倍数每次加1,p数组的第 阅读全文
posted @ 2021-02-21 23:00 Carrot_Rui 阅读(57) 评论(0) 推荐(0)
摘要: 水 #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int N = 1e4 + 9; int n ; struct node{ int data; // 数值 int rank 阅读全文
posted @ 2021-02-21 22:59 Carrot_Rui 阅读(42) 评论(0) 推荐(0)
摘要: 水 //fib高精度用二维数组存 #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> using namespace std; int n,len=1,f[5003][5003]; //f[k][i] - 阅读全文
posted @ 2021-02-21 22:57 Carrot_Rui 阅读(68) 评论(0) 推荐(0)
摘要: 水 我们知道对于幂运算有: ab%k=(a%k)(b%k)%k 如: 5 * 6 % 4 = (1+4)(2+4)% 4 = 1 * 2 % 4 因为 1 * 4 和 2 * 4 和4 * 4模4都为0 位运算加速 // 求 m^k mod p,时间复杂度 O(logk)。 int qmi(int 阅读全文
posted @ 2021-02-21 22:55 Carrot_Rui 阅读(56) 评论(0) 推荐(0)
摘要: 前缀和: 一维: #define N 10004 void _1(){ int n, a[N], ans[N]; scanf("%d",&n); for(int i = 1; i <= n; i++){scanf("%d",a+i);ans[i] += ans[i-1] + a[i] ;} // f 阅读全文
posted @ 2021-02-21 22:53 Carrot_Rui 阅读(76) 评论(0) 推荐(0)
摘要: 模板: bool check(int x) {/* ... */} // 检查x是否满足某种性质 // 区间[l, r]被划分成[l, mid]和[mid + 1, r]时使用: int bsearch_1(int l, int r) { while (l < r){ int mid = l + r 阅读全文
posted @ 2021-02-21 22:48 Carrot_Rui 阅读(29) 评论(0) 推荐(0)
摘要: 广度优先搜索: 水 广度优先搜索会先考虑每种状态的和初始状态的距离说人话:与初始状态越接近的情况就越会优先考虑,每个状态要做的事情就是上个状态的扩展。经常是有队列实现,每次取出队首找出队首的扩展状态将其压入队列,知道队列空。 广搜模板: int bfs(int sx,int sy) { Q.push 阅读全文
posted @ 2021-02-21 22:43 Carrot_Rui 阅读(140) 评论(0) 推荐(0)