重新做了一下这道并查集的题目,关键要点是抓住这种循环的关系和模运算的通性,进而利用加权并查集 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; cons ...
分类:
其他好文 时间:
2020-07-15 23:39:09
阅读次数:
63
题目链接:http://poj.org/problem?id=2482 给出每个点框定的区域,求区域叠加的最大值,可以通过如下算法: 将每个可行点都标记,记录这些点上的权值,维护一个叶结点是一个权值点的线段树,更新的时候注意,由于所有的点都是可行点,所以右边界要在最后删除,遇到同样的x坐标的,优先叠 ...
分类:
编程语言 时间:
2020-07-15 15:23:49
阅读次数:
68
解题思路: 题目要求的二叉树的 从上至下 打印(即按层打印),又称为二叉树的 广度优先搜索(BFS)。 BFS 通常借助 队列 的先入先出特性来实现。 算法流程:特例处理: 当树的根节点为空,则直接返回空列表 [] ;初始化: 打印结果列表 res = [] ,包含根节点的队列 queue = [r ...
分类:
其他好文 时间:
2020-07-14 00:36:31
阅读次数:
69
BFS广度遍历代码模板 /** 广度遍历代码模板 */ public class TestBFS { public List<List<Integer>> bsf(TreeNode root) { // 如果节点为空 if (root == null) { return null; } List<L ...
分类:
其他好文 时间:
2020-07-13 18:26:06
阅读次数:
70
知识点: DP,差分,Bfs 原题面 双倍经验 P3943 星空。 将此题代码交过去可直接 AC,但 P3943 数据较弱,没有卡掉错误的背包解法。 完全背包解法错误原因 详见 题解 P3943 【星空】 - Epworth 的博客。 题意简述 给定一长度为 \(n\) 的 $0$ 串,给定 \(k ...
分类:
其他好文 时间:
2020-07-13 09:25:09
阅读次数:
65
BFS和DFS DFS遍历使用递归(隐式使用栈): void dfs(TreeNode root) { if (root == null) { return; } dfs(root.left); dfs(root.right); } BFS遍历使用队列 void bfs(TreeNode root) ...
分类:
其他好文 时间:
2020-07-12 22:04:02
阅读次数:
66
列一下hdu,poj,CF上常见的Stirling数相关的习题(补充完善中): hdu2643 hdu3625 hdu4372 hdu4045 POJ1430 POJ2621 CF932E CF961G CF960G ...
分类:
其他好文 时间:
2020-07-12 16:52:18
阅读次数:
64
题目描述 给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则: 每次转换只能改变一个字母。 转换过程中的中间单词必须是字典中的单词。 说明: 如果不存在这样的转换序列,返回 0。 所有单词具有相同 ...
分类:
其他好文 时间:
2020-07-12 12:22:49
阅读次数:
41
A Bug's Life Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different gend ...
分类:
其他好文 时间:
2020-07-11 17:33:44
阅读次数:
54
A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given two strings A, B and one integer K, we define S, a set of tripl ...
分类:
编程语言 时间:
2020-07-11 13:09:02
阅读次数:
71