文章分类 - 算法蒟蒻
摘要:【欧拉函数】 运用 公式求欧拉函数 时间复杂度 O(sqrt(n)) //公式法求欧拉函数 #include<bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; int n; ll a; signed
阅读全文
摘要:【自动机】DFA 概念与定义 自动机是一个对信号序列进行判定的数学模型 ->结构:有向图 序列自动机 定义 举例 思路 代码示例 int pre[N],suf[N]; pre[0]=0;suf[n+1]=n+1;//初始化序列自动机 //之前:从前往后扫 for(int i=1;i<=n;i++){
阅读全文
摘要:【因数】(理论知识) 求约数:试除法 时间复杂度 O(sqrt(n)) 思路 约数是成对出现的->只枚举小的一个 代码 #include<bits/stdc++.h> using namespace std; typedef long long ll; int t; int a; vector<in
阅读全文
摘要:【思维题】 打表多造数据很关键!!!!!!! 观察一种东西的特殊性质 奇数 偶数(区域/总) 2的幂次 倍数 质数 最大值 最小值(序列) 取模 对称 一直+-*/再还原 左右最小/最大/最近/最远 头尾01 逆序对 多观察规律 多想性质 多用代码行数短的做法 注意分类讨论!!! Scarecrow
阅读全文
摘要:【质数】 判定质数:试除法 时间复杂度 O(sqrt(n)) 思路 代码 #include<bits/stdc++.h> using namespace std; typedef long long ll; int t,a; bool is_prime(int n){ if(n<2) return
阅读全文
摘要:【树的直径】 求解方法 //搜索思路 (1)任选一点x,求出距离x最远的点y 然后再以y为起点,求出距离y最远的点的距离 //树形DP思路 (2)树的直径maxd就是所有节点往下走的最大距离与次大距离之和中的最大值 即maxd=max(dis1[i]+dis2[i]) (例题)旅游规划 https:
阅读全文
摘要:【数学】 收录一些用 数学处理手法/纯数学计算推规律 的题目 最小值 https://acm.hdu.edu.cn/contest/problem?cid=1176&pid=1012 题目大意 思路 【看到绝对值】第一个想法是去绝对值->分类讨论 【找序列两数相减绝对值最小】排序,求差分,差分序列最
阅读全文
摘要:【树状数组】 模版代码 struct FenwickTree { vector<int> tree; int size; FenwickTree(int n){ size=n; tree.resize(n+1,0); } void update(int pos, int delta){ for(;p
阅读全文
摘要:【算法竞赛】一些好用的模版/注意要点 火车头(2025.10.03更新) #include<bits/stdc++.h> using namespace std; #define endl '\n' #define whiteink signed main #define fi first #def
阅读全文