摘要: 1、基础排序(cmp函数自定义排序) `struct Ren { int a;int b; }ren[1000010]; bool cmp(const Ren& i, const Ren& j) { if (i.zhi < j.zhi) { return true; } else { if (i.z 阅读全文
posted @ 2025-10-06 16:50 yubai111 阅读(1) 评论(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 阅读(4) 评论(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 阅读(6) 评论(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 阅读(6) 评论(0) 推荐(0)
摘要: 题目来源:https://www.luogu.com.cn/problem/P1363 答案导航:https://www.luogu.com.cn/record/232043052 一道简单的图论(误)?搜索(正确),挂的标签是dfs但是其实bfs好用很多, *思路:因为这题中理论上是个无限延展的图 阅读全文
posted @ 2025-08-20 10:26 yubai111 阅读(6) 评论(0) 推荐(0)
摘要: 题目来源:https://www.luogu.com.cn/problem/P4017 答案导航:https://www.luogu.com.cn/record/231620242 这道题的dp几乎不像是dp,转移非常好想,可能这也是它复合但简单的原因。 debug:我的错处在于误以为食物链只有一个 阅读全文
posted @ 2025-08-18 11:50 yubai111 阅读(4) 评论(0) 推荐(0)
摘要: 基础思路:这一part主要有两个算法,prim和kruskal,两者都是采用的贪心(p是贪最近的新点,k是贪最小的新边) 1、prim(每次拿一个新的节点,并用该节点辐射所有未用过的点把它们之间的距离更新进dis,然后在下一轮中遍历所有这些边,取最近的新点): ` const int NUM = 1 阅读全文
posted @ 2025-08-17 23:12 yubai111 阅读(10) 评论(0) 推荐(0)
摘要: 基础思路:哈希是一种映射算法,也类似于‘进制’处理,一般会是131、13331进制,然后MOD越大越稳定(越不容易映射重复) 哈希常用于字符串匹配,在给定区间匹配中表现良好,以下是经典款: const int P = 131; const int MOD = 998834567; int getha 阅读全文
posted @ 2025-08-16 23:54 yubai111 阅读(5) 评论(0) 推荐(0)
摘要: 基本思路:用于合并同类项,路径压缩使得它的时间复杂度极低 并查集的核心,用于寻找祖先: int find(int x) { if (p[x] != x) { p[x] = find(p[x]); } return p[x]; } 用于合并(易错点是合并一定要合并祖先而非本人) void merge( 阅读全文
posted @ 2025-08-16 21:25 yubai111 阅读(6) 评论(0) 推荐(0)
摘要: 题目导航:https://www.luogu.com.cn/problem/P3916 `unordered_map<int, vector>mp; int rr[100010]; int ans[100010]; int allnum; int sn; void dfs(int x) { rr[x 阅读全文
posted @ 2025-08-15 18:45 yubai111 阅读(5) 评论(0) 推荐(0)