03 2021 档案
摘要://滑动窗口 单调队列#include<cstdio>#define ll long long#define N 1000001using namespace std;int n,k;ll a[N],q[N],q2[N]; //q存值 int b[N],b2[N]; //b存编号 void find
阅读全文
摘要:###定义 ####二分图 二分图(bipartite graph)指的是满足 图的所有结点可以分成两个集合,每个集合内的点没有连边,两个集合之间可以有连边 的图 。 ######判断一张图是否是二分图? 从一个集合出发,回到这个集合的路径的长度一定为奇数。 (必要条件) ####二分图匹配 一个匹
阅读全文
摘要:思路 通过两次bfs实现。 第一次判断人是否能从起点走到箱子所在位置的四周 第二次判断箱子是否能走到下一个位置 注意 箱子转弯时,人要绕到下一次推箱子的位置,若不能走到直接return #include<bits/stdc++.h> //推箱子 #define ll long long#define
阅读全文
摘要:dfs(深度优先搜索)即从每一个位置开始,逐步搜索下一个可行解,直到找到答案或者因不合法而返回 常见应用 走迷宫问题(小规模) 可以通过暴力+剪枝解决的问题 eg.素数环问题 // 素数环问题 clockwise||anticlockwise 直接搜索 //二维数组不宜用回溯,因为回溯时部分元素会被
阅读全文
摘要:bfs(宽度优先搜索)即从每个点出发,找到它之后的所有可行的点,加入队列中。 常见应用: 走迷宫问题 下一步状态可由上一步状态转移得到的问题 代码 #include<bits/c++.h> //bfs using namespace std; int w,h; char a[22][22]; int
阅读全文
摘要://威佐夫博弈(Wythoff Game):有两堆各若干个物品//两个人轮流从某一堆或同时从两堆中取同样多的物品//规定每次至少取一个,多者不限,最后取光者得胜。 #include<bits/stdc++.h>using namespace std;int T,n,x;int a,b;double
阅读全文
摘要:// 求阶乘逆元 //考虑 (a/b)%mod 其中a和b都是很大的数 在得到a和b前都要%mod //如果直接除,会丢失精度 //解决办法:转化成 a*(b在模mod状态下的逆元) (这样a/b <=> a*b的逆元) //由费马小定理:a^(p-1)=1(mod p) //p为素数 //可知a在
阅读全文
摘要://s-nim//所有游戏的nim和=每个游戏的SG函数值异或 //对于一个局面,当且仅当A1 xor A2 xor … xor AN =0时,该局面为P局面(必败)//当nim和为0,ai xor nim-sum也不改变ai的值 //当nim和不为零,找到其最高位(必为1),找到ai对应位为1,将
阅读全文
摘要://母函数的应用 ac两道基本+想通两种变式 //不写完,不睡觉 //0:27写完啦 1A 写个小小总结 //1.element0~n-1 任意个:直接套模板//2.element是特定元素的集合 个数任意:定义一个数组并初始化。元素无规律,下标有规律//3.element特定 个数有限制:用结构体
阅读全文
摘要://二分查找//也可以用lower_bound/upper_bound实现 #include<cstdio>#include<algorithm>using namespace std; const int N = 1000001;int n,m;int a[N],b[N]; int find(in
阅读全文
摘要://求所有<=n的质数a 埃筛 //证明:设 n=a*b;(a<=b) //则 a<=sqrt(n) #include<cstdio> #include<cmath>#include<cstring>using namespace std;bool prime[100001];int n; int
阅读全文
摘要:#include<cstdio>//卡特兰数 + 记忆化搜索//h(n)=C(2n,n)/(n+1)//卡特兰数背景://1.在圆上有2N个不同的点 N条线段把这些点连接 每个点连一条 使所有的线段都不相交 //2.对凸n+2边形进行不同的三角形分割(只连接顶点对形成n个三角形)数//3.n个数入栈
阅读全文
摘要://高精度加法#include<cstdio>#include<string>#include<iostream>using namespace std;string x,y;int ans[1005],a[1004],b[1001]; int max(int a,int b){ if(a>b) r
阅读全文
摘要://构造一个单调的函数,且函数值容易求,这时问题的解可以通过二分来求出 #include<bits/stdc++.h> #define ll long long using namespace std; const int N = 1000001; int n,m; int a[N]; ll pre
阅读全文
摘要:#include<bits/stdc++.h> //普通括号匹配 using namespace std;int T;string s; int main(){ cin>>T; while(T--){ bool f=1; cin>>s; stack<char>q; for(int i=0;i<s.l
阅读全文
摘要://并查集模板 亲戚 #include<cstdio>using namespace std;int father[5005]; int f(int x){ //寻找每个结点的父亲结点 int r=x; while(father[r]!=r){ r=father[r]; } return r;} i
阅读全文
摘要://第k小整数 c++写法 #include<cstdio>#include<algorithm>using namespace std;int a[10001]; int main(){ int n,k; scanf("%d%d",&n,&k); for(int i=0;i<n;i++) scan
阅读全文
摘要:STL容器的基本用法 迭代器:用于遍历容器中数据的对象。按预先定义的顺序移动,所以不宜用it<s.end(); (封装过的指针) queue FIFOq.empty() 空返回1 不空返回0q.size() 队列大小q.push(元素名)q.pop() q.front()q.back()清空:循环出
阅读全文
摘要:写好暴力代码 再编译运行 写好要提交的代码 再编译运行 写随机生成数据的代码 #include<bits/stdc++.h> //datausing namespace std; int main(){ freopen("data.in","w",stdout); puts("1");// for(
阅读全文
摘要://f[n]=(A*f[n-1]+B*f[n-2])%7 //n<=1e8 //引申:已知递推式 f[n]=a0*f[n-1]+a1*f[n-2]+...+ap*f[n-p+1]//其中n范围较大(用记忆化搜索等等方法会超时)//这时考虑 O(logn)时间复杂度的算法——矩阵ksm! //#inc
阅读全文