05 2024 档案
摘要:题目 链接:https://codeforces.com/problemset/problem/1795/C or https://www.luogu.com.cn/problem/CF1795C 总思路: 利用数组记录a[N], b[N]分别记录每杯茶的量,每个人喝的量,然后每个人喝的量进行前缀和
阅读全文
摘要:题目: 有一个巧妙的解法: 考虑这个问题, 从一个没有限制的从1开始的递增序列找出第k个数, 显然就是十进制的k。而这里则可以定义新的进制为 "012356789" 9进制, 那么k对应的就是这个特殊的九进制数, 我们只需要把它转换为十进制就行。 代码: #define _CRT_SECURE_NO
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1842/C or https://www.luogu.com.cn/problem/CF1842C 大概的思路就是利用dp[i]记录前i个数据最多消掉的数字个数,然后对∀j:a[i] == a[j] && j
阅读全文
摘要:题目: 链接:https://www.luogu.com.cn/problem/CF1857E or https://codeforces.com/problemset/problem/1857/E 思路 我的思路可能比较复杂: 首先由于覆盖的是整点,那么可以想到排序后用前缀和,比如1 4 3 --
阅读全文
摘要:非常有意思的一道思维题!!!! 先上两个题解: 题解1: 题解2: 总的思路就是伪“前缀和”,然后维护选0还是选1的异或和就够了。 如果改变,就直接像前缀和那样改,证明理由就是0^a = a ;a^a =0; 代码: #define _CRT_SECURE_NO_WARNINGS #include<
阅读全文
摘要:代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #inclu
阅读全文
摘要:有点水,但是细究还是有点意思的题目 https://www.luogu.com.cn/problem/P1474 一开始的代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include<algorith
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/CF212E https://codeforces.com/problemset/problem/212/E 题目: 思路: 首先题目说要保证最大的数量,并且每个颜色的点至少有一个,那么很显然染色的点有n-1个,且唯一没染色的点
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1944 题目: 思路:注意题目里说的: 1.(),[]是括号匹配的字符串。 2.若A是括号匹配的串,则(A),[A]是括号匹配的字符串。 3.若A,B是括号匹配的字符串,则AB也是括号匹配的字符串。 所以设dp[i]是以i结
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1929 题目: 思路:动态规划:以times[i]表示跳到第i号台阶的最小步数。 如果height[i] == height[i-1] + 1那么显然有times[i] = times[i-1] + 1 然后是遍历的状态转移
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1853 题目: 总的思路就是完全背包模板加上空间优化 完全背包参考:https://blog.csdn.net/qq_40802813/article/details/119609917 空间优化见代码 #define _C
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1057 思路:左手倒右手,建立递推方程 建立初始参数:定义dp[j][k]是第k次,以j结尾的方法,就是传k次最后传到j的方法。 那么状态转移方程:dp[j][k]=dp[next][k-1]+dp[before][k-1]
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1807 其实没什么难的,注意点:拓扑排序,把非1的入度为0的点及其衍生点全删了,不然会到一半无法拓扑下去。 关键在于我之前那个删点的操作,先看错误代码: ... void clearpoint(ll ix) { for (l
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P3366 模板题: kruskal代码: 核心是对边的排序,遍历,选择。 #include<iostream> #include<vector> #include<algorithm> #include<math.h> #in
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1140 题目: 思路:设置递推状态:dp[i][j]表示a的前i个碱基和b的前j个碱基配对的最大值。 那么递推: 1.ans1设置为dp[i-1][j-1]+val[a[i]][b[j]]就是说a[i]和b[j]可以凑一对,
阅读全文
摘要:思路:由于是一棵n节点,n-1边的图,所以必然没有环,那么从任何一个节点出发都必然达到另外一个节点。 如果子节点的dp大于0,那么父节点加上,否则砍掉(不加) 同时如果visit过了那就不用visit,总体复杂度为O(n)。 代码: #include<iostream> #include<vecto
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1044 两种很好的思路: 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #inc
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1347 题目: 由于数据量很小,所以可以在线处理数据。 首先判断有没有环(这里不一定可以根据拓扑排序写出来,因为有的环可以只有部分节点,所以必须遍历所有节点的路径,判断有没有环); 然后查看入度为0的点,如果没有环而且入度为
阅读全文
摘要:#include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #include<string.h> #include<iomanip> #incl
阅读全文
摘要:简单的一道深搜: 思路:让每个有奶牛的农场沿着道路跑下去,跑到的农场加上root地方的奶牛数量,最后统计能有k头奶牛的农场数量就是答案 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #incl
阅读全文
摘要:拓扑排序,有向图 记录每个点的入度,进行拓扑排序 然后怎么计算ans? 通过每个点的入度传递到子节点,在食物链的末尾加上即可,注意求余。 原理: 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h>
阅读全文
摘要:简记: 1.参考学习: https://blog.csdn.net/qaqwqaqwq/article/details/126124806 https://www.cnblogs.com/cjjsb/p/9771868.html 2.代码: #include<iostream> #include<v
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P1352 树形dp板子,感觉很巧妙,利用01表示是否取 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1833/D 题面: 细节:分类讨论 约定记号:a,b[c,d],e,f:选定cd为反向序列。 ①当最大值出现在最后一个元素 可以确定:必然的形式是[a,...,p],maxn,右括号位置一定不变,那么就移动左
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1773/E 思路 首先先得出最终序列,因为它具有唯一性,然后再根据其中的前后关系来判断原来的数列需要切几刀。然后再根据切几刀形成的最终数列判断需要合并几次。 例如: 目标数列是ABCDEF,而给出的某两段序列
阅读全文
摘要:链接:https://www.luogu.com.cn/problem/P2341 题目: 思路: tarjan缩点:把所有强连通分量缩成一个点,然后统计出度为0的缩点,如果只有一个,那么能成为明星的数量就是该缩点扩充后的个数;如果不止一个,那就是0. 代码: 额,就是不知道为什么debug了两节课
阅读全文
摘要:Tarjan模板 #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #include<string.h> #include<ioman
阅读全文
摘要:https://www.luogu.com.cn/problem/P3388 求割点模板 #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<strin
阅读全文
摘要:题面: 链接:https://www.luogu.com.cn/problem/P3916 思路:反向遍历图 啊卡了好久,如果正序来的话还得考虑环和先后次序的问题 代码: #include<iostream> #include<vector> #include<algorithm> #include
阅读全文
摘要:希冀平台: 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #include<string.h> #include<ioma
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1840/D 洛谷链接:https://www.luogu.com.cn/problem/CF1840D 思路: 这个题目之前好像碰到过类似的,感觉就是对长度二分,然后遍历,注意有个坑的点在于应该是2*len因
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1860/C 洛谷链接:https://www.luogu.com.cn/problem/CF1860C 相关知识点复习:LIS最长上升子序列 链接:https://blog.csdn.net/lxt_Luci
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1878/E 洛谷链接:https://www.luogu.com.cn/problem/CF1878E 知识点:st表+二分(我不知道为什么有的题解说不用二分...反正我的在第11个测试点会TLE) 思路就是
阅读全文
摘要:题面: 链接:https://codeforces.com/problemset/problem/1893/A 洛谷链接:https://www.luogu.com.cn/problem/CF1893A 思路:逆着推 有一个非常重要的结论得观察出来: 所以当倒过来推的时候(b->a),同理可以直接取
阅读全文
摘要:电子书板子: 希冀平台: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #include<string.h> #include<i
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1896/C 洛谷:https://www.luogu.com.cn/problem/CF1896C 这题疑似有点水了?为什么还有绿题hhhh 思路:结构体+排序 首先对a,b各自排序:取b的下x和a的上x比较
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1901/C 洛谷链接:https://www.luogu.com.cn/problem/CF1901C 思路: 首先去重:这里建议分清楚总操作数n和元素总数cnt。 然后把去重的元素放在数组中,sort让它升
阅读全文
摘要:链接:https://codeforces.com/problemset/problem/1903/C 洛谷链接(有翻译):https://www.luogu.com.cn/problem/CF1903C 解答: 观察可知:如果后面连续的和大于等于0,那么后面就可以连成一段(贪心),就是说因为前面每
阅读全文