随笔分类 -  算法竞赛

摘要:赛时困得睡着了 B题 https://www.acwing.com/problem/content/5562/ 第二题赛事一直在想模拟加贪心,却发现非常难实现,我们需要转变思维,这时候一般有3种可能 双指针?二分?dp? 后来清醒了一点我们判断一个答案是不是合法很容易,我们再考虑答案求最大值,显然具 阅读全文
posted @ 2024-03-26 22:40 potential-star 阅读(33) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/531/ #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 12, M = 1 < 阅读全文
posted @ 2024-03-22 02:12 potential-star 阅读(28) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/description/2071/ 每次合并的时候需要开一个新点去实现信息的无后效性,也就是合并之前的两个连通块信息是无法共享的,发现这样开点连边最后 形成一棵树,每次我们将信息传递到新点,也是两个合并点的lca,这使得最 阅读全文
posted @ 2024-03-21 16:06 potential-star 阅读(32) 评论(0) 推荐(0)
摘要:https://zhuanlan.zhihu.com/p/340514421 https://blog.csdn.net/Emm_Titan/article/details/124035796 https://www.cnblogs.com/TianMeng-hyl/p/14972355.html 阅读全文
posted @ 2024-03-15 20:11 potential-star 阅读(17) 评论(0) 推荐(0)
摘要:双指针的题目往往是看起来需要O(n),我们一般枚举一个指针,然后我们发现另一个指针不走回头路,不论是哪个方向,这样我们的时间复杂度就是O(n). 从例题来看: 给定一个字符串,我们希望找到最短长度区间能包含所有字母类型。 核心:对于左端点固定的时候,我们找到最小的r,然后我们考虑i右移动一位,这时候 阅读全文
posted @ 2024-03-10 22:28 potential-star 阅读(45) 评论(0) 推荐(0)
摘要:链接:https://ac.nowcoder.com/acm/contest/69510/G 来源:牛客网 你在一个星球上,外星人amiloac想让你管理一条河流,该河流有\(x\)段,每两段之间有一个挡板隔开,每一段都有各自的颜色\(a\)。你需要管理\(q\)天,每一天你需要做以下的一种操作。 阅读全文
posted @ 2024-03-05 23:18 potential-star 阅读(66) 评论(0) 推荐(0)
摘要:对于一个字符串 \(S\),我们定义 \(S\) 的分值 \(f(S)\) 为 \(S\) 中恰好出现一次的字符个数。 例如 \(f (“aba”) = 1\),\(f (“abc”) = 3\), \(f (“aaa”) = 0\)。 现在给定一个字符串 \(S[0…n-1]\)(长度为 \(n\ 阅读全文
posted @ 2024-01-30 13:25 potential-star 阅读(41) 评论(0) 推荐(0)
摘要:hh的项链:不带修改维护区间种类数 https://www.luogu.com.cn/problem/P1972 树状数组做法 https://zhuanlan.zhihu.com/p/272804539 #include<bits/stdc++.h> using namespace std; in 阅读全文
posted @ 2023-12-22 22:34 potential-star 阅读(32) 评论(0) 推荐(0)
摘要:SDUT 校赛题目 Description 给定正整数 \(n\),计算 \(n\) 个元素的集合 \(\{1,2,\cdots,n\}\),所有非空子集和的乘积取模 \(998 \, 244 \, 353\) 后的结果。 Input 一个正整数 \(n\) \((1\le n\le200)\),代 阅读全文
posted @ 2023-12-14 15:30 potential-star 阅读(104) 评论(0) 推荐(0)
摘要:对于种类并查集主要是考虑清楚到根节点距离分为几类,每一类的意义 有的题目相出d数组的含义才能想到用带权并查集 //find函数需要变化 int find(int x) { if (p[x] != x) { int root = find(p[x]); d[x] += d[p[x]]; p[x] = 阅读全文
posted @ 2023-12-09 21:24 potential-star 阅读(25) 评论(0) 推荐(0)
摘要:scc:极大的强连通子图(两两相互可达) const int N=10010; int n,m,a,b; vector<int> e[N]; int dfn[N],low[N],tot; int stk[N],instk[N],top; int scc[N],siz[N],cnt; void tar 阅读全文
posted @ 2023-12-09 01:59 potential-star 阅读(21) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P4316 本题暂时只写了用期望dp经典套路,套上期望DP的基本套路,设dp(u)为到达u点的期望长度。 期望dp,也叫概率dp 一般来说,期望dp找到正确的状态后,转移是比较容易想到的。 但一般情况下,状态一定是“可数”的 事实上, 阅读全文
posted @ 2023-12-05 00:56 potential-star 阅读(32) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/description/4012/ Acwing long double卡常,注意cin读小数。 #include <bits/stdc++.h> using namespace std; #define ll long 阅读全文
posted @ 2023-12-04 23:11 potential-star 阅读(38) 评论(0) 推荐(0)
摘要:https://www.acwing.com/activity/content/competition/problem_list/3648/ B题收获: 1.利用题目告诉的结论:1e9范围质数之差小于300 2.一个数不被2-a的任何数整除 等价于他的最小质因子需要大于a c题:初步宏观思路:不难想 阅读全文
posted @ 2023-12-03 20:53 potential-star 阅读(29) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/4010/ http://118.190.20.162/view.page?gpid=T130 脑子一热抱着玩的心态试了一下三分,当然炸了,就当初认识三分了。 正解是考虑p的变化的影响,p变成p+1的时候,答案的值取决于 阅读全文
posted @ 2023-11-30 17:39 potential-star 阅读(44) 评论(0) 推荐(0)
摘要:题意是这样的,给你一个串,只有 T 和 W。令 T=2,W=1,将其变成数字串。然后每次给一个k,问是否存在一个子段和为k 一筐题目: https://www.acwing.com/problem/content/description/4040/ 基础版本,只需要存在性并输出任意一组合法解 htt 阅读全文
posted @ 2023-11-28 23:16 potential-star 阅读(39) 评论(0) 推荐(0)
摘要:无限制最长连续的子序列和 https://www.acwing.com/problem/content/description/1481/ dp[i]=max(dp[i-1]+a[i],a[i]); 最终结果也就是在dp数组线性扫描找出最大值 int pos=max_element(dp+1,dp+ 阅读全文
posted @ 2023-11-28 21:28 potential-star 阅读(58) 评论(0) 推荐(0)