随笔分类 - 算法大全
摘要:#include<bits/stdc++.h> #define int long long using namespace std; std::vector<int> manacher(std::string s) { std::string t = "#"; for (auto c : s) {
阅读全文
摘要:全局变量 string a,b; int kmp_next[1000010]; // next数组 初始化next数组 void getNext(int m){ int j = 0; // 初始化next[0]的值 kmp_next[0] = 0; for(int i=1; i<m; ++i){ /
阅读全文
摘要:int lowbit(int x){return x&(-x);} bool check(int x){ if(lowbit(x)!=x)return true; else return false; }
阅读全文
摘要:不断的去插入删除线段,问你有无两个线段是不相交的 个人认为很好的一道题训练multiset #include<bits/stdc++.h> using namespace std; multiset<int>sl,sr; int main(){ ios::sync_with_stdio(false)
阅读全文
摘要:for(int j=2;j<=sqrt(x);j++){ while(!(x%j)){ mp[j]++; x/=j; } } if(x!=1){ mp[x]++; }
阅读全文
摘要:typedef long long LL; LL pow(LL a, LL n, LL m){ LL res = 1; while(n){ if(n & 1){ res = res * a % m; } a = a * a % m; n >>= 1; } return res;
阅读全文
摘要:__int128 li = -2e18,ri = 2e18; //向上找最小值 while(li<ri) { __int128 mid = (li+ri-1)/2; if(a+mid*m>=l) ri=mid; else li = mid+1; } __int128 lj = -2e18,rj =
阅读全文
摘要:能承载39位的大数 #define int long long必开 template <typename _Tp> inline void read(_Tp&x) {//输入 char ch;bool flag=0;x=0; while(ch=getchar(),!isdigit(ch)) if(c
阅读全文
摘要:int mergeSort(vector<int>& nums, int left, int right) { if (left >= right) return 0; int mid = left + (right - left) / 2; // 分治递归 long long count = me
阅读全文
摘要:#include<bits/stdc++.h> #define int long long using namespace std; int n,p; int gcd(int a,int b,int &x,int &y){ if(b==0){ x=1; y=0; return a; } int d=
阅读全文
摘要:模板 #include<bits/stdc++.h> using namespace std; const int N=1e8+10; int p[N]; bitset<N>vis; int n; void ola(){ int cnt=0; for(int i=2;i<=N;i++){ if(!v
阅读全文
摘要:思路:先用素数筛把20000以内的素数筛出来,然后枚举两个素数 //哥德巴赫猜想(升级) #include<bits/stdc++.h> using namespace std; const int N=20005; bitset<N>vis; vector<int>p; void prime(){
阅读全文
摘要:哥德巴赫猜想:任意一个大于2的偶数都可以写成两个质数之和 思路:枚举质数 //哥德巴赫猜想 #include<bits/stdc++.h> using namespace std; bool check(int x){ if(x<=1)return false; for(int i=2;i<=sqr
阅读全文
摘要:模板代码 #include<bits/stdc++.h> #define int long long using namespace std; const int N=1e5+10; vector<pair<int,int>>a[N]; int dis[N],vis[N]; int n,m; voi
阅读全文
摘要:邮递员送信 题目描述 有一个邮递员要送东西,邮局在节点 \(1\)。他总共要送 \(n-1\) 样东西,其目的地分别是节点 \(2\) 到节点 \(n\)。由于这个城市的交通比较繁忙,因此所有的道路都是单行的,共有 \(m\) 条道路。这个邮递员每次只能带一样东西,并且运送每件物品过后必须返回邮局。
阅读全文
摘要:租用游艇 题目描述 长江游艇俱乐部在长江上设置了 \(n\) 个游艇出租站 \(1,2,\cdots,n\)。游客可在这些游艇出租站租用游艇,并在下游的任何一个游艇出租站归还游艇。游艇出租站 \(i\) 到游艇出租站 \(j\) 之间的租金为 \(r(i,j)\)(\(1\le i\lt j\le
阅读全文
摘要:简单的dfs从1节点开始往下深搜,然后回溯记录路径 #include<bits/stdc++.h> using namespace std; const int N=1e4+10; vector<int>a[N]; int n,m; vector<int>p; void dfs(int x,int
阅读全文
摘要:从一个点开始,每次都找与这个点最近的点,近队列,直到队列为空,是关于点的算法,时间复杂度为nlog(n) 模板: #define int long long using namespace std; const int N=9e5+10; int n,m; vector<pair<int,int>>
阅读全文
摘要:平衡字符串的性质 将左括号看出1,右括号看成-1 (1)最后加起来是0 (2)中间一直要是正数 所以代码如下 using namespace std; int n; int dx[2]={1,-1}; int ans=0; void dfs(int cur,int x){ if(x<0)return
阅读全文
摘要:next_permutation全排列公式 数据不大,直接暴力全排列模拟出数据即可 using namespace std; int p[9]={1,2,3,4,5,6,7,8,9}; int main(){ int a,b,c; cin>>a>>b>>c; int cnt=0; do{ int x
阅读全文