摘要: 1、加法 vector<int> add(vector<int> &A, vector<int> &B) { if (A.size() < B.size()) { return add(B, A); } vector<int> C;int t = 0;//t作为两个相加的中转处 for (int i 阅读全文
posted @ 2025-10-15 22:07 yubai111 阅读(8) 评论(0) 推荐(0)
摘要: ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //取消同步流 阅读全文
posted @ 2025-10-15 20:55 yubai111 阅读(3) 评论(0) 推荐(0)
摘要: 1、二分图匹配问题(判断是否二分图可以使用并查集) ` int n1, n2, m; int h[500], e[100010],ne[100010], idx = 0; int st[510], match[510];//st 标记是否递归找过, match[x]:和 x 编号的男生的编号 voi 阅读全文
posted @ 2025-10-15 20:55 yubai111 阅读(4) 评论(0) 推荐(0)
摘要: 1、dfs(该模板模拟的是数字的全排列,本质是迭代) ` const int N = 10; int res[N];int state[N];//res存放排列,state存放该数字是否用过 int n; void dfs(int u) { if (u > n) { for (int i = 1; 阅读全文
posted @ 2025-10-08 11:38 yubai111 阅读(12) 评论(0) 推荐(0)
摘要: 基础思路:Dijkstra是贪心用最短的边去更新其他相邻边,而spfa是上次更新的终点去更新其他边,bellman-ford则是非常暴力的每次更新所有边 1、Dijkstra(非负单源、稠密或大规模稀疏,类bfs+贪心,每次取距离当前点距离最小的新点,用新点来更新‘与新点相连的所有点’到起点的距离) 阅读全文
posted @ 2025-10-08 10:57 yubai111 阅读(6) 评论(0) 推荐(0)
摘要: 1、Trie ` const int N = 100010; int idx; // 各个节点的编号,根节点编号为0 int son[N][26];//Trie 树本身 int cnt[N];//以编号为 x 为结尾的字符串的个数 int n; void insert(string s){ int 阅读全文
posted @ 2025-10-07 22:04 yubai111 阅读(5) 评论(0) 推荐(0)
摘要: 1、基础排序(cmp函数自定义排序,sort的复杂度几乎为nlogn) `struct Ren { int a;int b; }ren[1000010]; bool cmp(const Ren& i, const Ren& j) { if (i.zhi < j.zhi) { return true; 阅读全文
posted @ 2025-10-06 16:51 yubai111 阅读(5) 评论(0) 推荐(0)
摘要: 题目来源:https://www.luogu.com.cn/problem/P1990 经典递推,代码很短所以放这了,但是递推或dp的初学时会很难想这个思路: `#include define int long long using namespace std; int dp[1000010][2] 阅读全文
posted @ 2025-09-06 18:32 yubai111 阅读(10) 评论(0) 推荐(0)
摘要: 题目来源:https://www.luogu.com.cn/problem/P1002 这道题的基础框架: for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i == 0 && j == 0) continue; if 阅读全文
posted @ 2025-08-29 12:27 yubai111 阅读(22) 评论(0) 推荐(0)
摘要: 题目来源:https://www.luogu.com.cn/problem/P1194 答案导航:https://www.luogu.com.cn/record/233134764 一眼可见的最小生成树模板题,只需要在读入时稍微处理一点点,但就是这一点点我还是掉坑里了…… debug1:关于 for 阅读全文
posted @ 2025-08-25 20:58 yubai111 阅读(33) 评论(0) 推荐(0)