摘要: 题目链接:https://www.luogu.com.cn/problem/P2661 法一:并查集 当两个点x和y之间存在一条边,且他们的祖先都相同时,就会形成一个环,环的大小为dis[x]+dis[y]+1 #include <bits/stdc++.h> #define Pair pair<i 阅读全文
posted @ 2020-04-17 20:51 grass_lin 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题目链接: https://codeforces.com/contest/1339/problem/E 思路: 打表找规律,发现将三元组的第一个数转化成二进制之后,由低位到高位,将01变成11,10变成01,11,变成10 即为三元组的第二个数的二进制形式然后再异或求出第三个数。 该图为第16个数到 阅读全文
posted @ 2020-04-15 15:15 grass_lin 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题意: 给你一颗有n个节点的树,让你给每一条边赋一个值,最后要求每对叶子节点之间的简单路径中的边异或和为0, 问你最少要多少个数最多要多少个数 链接:https://codeforces.com/contest/1339/problem/D 思路: 以一个叶子节点为根跑一遍dfs,先考虑最少需要的数 阅读全文
posted @ 2020-04-15 09:30 grass_lin 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 题目大意: 题意就是告诉你一个数n,然后给你n个数,每个数满足1<=a[i]<=200,让你求最大的子序列,子序列由x个a和y个b和x个a构成。 链接:https://codeforces.com/contest/1335/problem/E2 思路: 我们先用一个vector v记录1-200中每 阅读全文
posted @ 2020-04-14 18:42 grass_lin 阅读(243) 评论(2) 推荐(0) 编辑
摘要: 题目链接: https://codeforces.com/contest/1327/problem/D 思路: 置换群和循环置换的概念:https://oi-wiki.org/math/permutation-group/ 由于p是1-n的一个排列,所以p可看成若干个不相交的环,而任意一个置换都可以 阅读全文
posted @ 2020-03-29 20:55 grass_lin 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 题目链接: https://www.luogu.com.cn/problem/P3178 思路: 树剖板子 代码: #include <bits/stdc++.h> #define ls node<<1 #define rs node<<1|1 using namespace std; typede 阅读全文
posted @ 2020-03-29 19:58 grass_lin 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 题目链接: https://www.luogu.com.cn/problem/P2590 思路: 树剖板子 代码: #include <bits/stdc++.h> #define ls node<<1 #define rs node<<1|1 #define l_q ls,l,mid #defin 阅读全文
posted @ 2020-03-29 19:54 grass_lin 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 题目链接: https://www.luogu.com.cn/problem/P3833 思路: 树剖板子题 代码: #include <bits/stdc++.h> #define ls node<<1,l,mid #define rs node<<1|1,mid+1,r using namesp 阅读全文
posted @ 2020-03-29 19:50 grass_lin 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 树链剖分常见题型: 一般对树上路径进行修改或者查询树上一段路径的值的和这类题可以用树链剖分, 树链剖分一般与线段树结合使用。 模板题: https://www.luogu.com.cn/problem/P3384 参考博客: https://www.cnblogs.com/ivanovcraft/p 阅读全文
posted @ 2020-03-28 21:40 grass_lin 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 模板题链接: https://www.luogu.com.cn/problem/P3379 参考博客: https://www.luogu.com.cn/blog/morslin/solution-p3379 代码: #include <iostream> #include <stdio.h> #i 阅读全文
posted @ 2020-03-28 10:36 grass_lin 阅读(151) 评论(0) 推荐(0) 编辑