摘要:
洛谷P1551 并查集 并查集有合并和查询两种基本操作 初始时,每个人的族群只有自己,随后有关系的人成为一个族群,选择一个族长 每次加入新的关系时,都会找到对应的族长。 查找操作 int find(int p1) { while (people[p1] != p1) { p1 = find(peop 阅读全文
摘要:
[JLOI2009] 二叉树问题 题目描述 如下图所示的一棵二叉树的深度、宽度及结点间距离分别为: 深度:$4$ 宽度:$4$ 结点 8 和 6 之间的距离:$8$ 结点 7 和 6 之间的距离:$3$ 其中宽度表示二叉树上同一层最多的结点个数,节点 $u, v$ 之间的距离表示从 $u$ 到 $v 阅读全文
摘要:
洛谷P1087 递归建立树,根据当前树的类型,选择“F”“B”“I” void build(int depth, int start, int end, int root){ if (depth >= n+1) return; int current = root; int flag = check 阅读全文
摘要:
洛谷P1030 输入中序先序序列,输出后序 l1-l2为当前中序遍历序列 l3-l4为当前后序遍历序列 #include<bits/stdc++.h> using namespace std; string a, b; struct node{ char self; int left, right; 阅读全文
摘要:
洛谷P1229 计算有多少个节点只有一个子节点。输出pow(2, n) #include<bits/stdc++.h> using namespace std; int main() { string a, b; int ans = 0; cin >> a >> b; int l = a.size( 阅读全文
摘要:
洛谷P1364 #include<bits/stdc++.h> using namespace std; struct node{ int value, left, right, p; node(int v, int l, int r): left(l), right(r), value(v){} 阅读全文
摘要:
洛谷P5076 #include<bits/stdc++.h> using namespace std; int n, root, cnt, opt, x; struct node{ int value, left, right, size, num; node(int l, int r, int 阅读全文
摘要:
洛谷P1827 输入中序先序序列,输出后序 l1-l2为当前中序遍历序列 l3-l4为当前先序遍历序列 #include<bits/stdc++.h> using namespace std; string a, b; void build(int l1, int l2, int l3, int l 阅读全文
摘要:
高精度 洛谷P2437 蜜蜂路线 这题是一道简单的求斐波那契数列题,但由于题目所给数字比较大,所以需要用到高精度。 主要代码 void fun() { for(int i = 0; i <= length; i++) { re[now][i] = re[now-1][i] + re[now-2][i 阅读全文
摘要:
这个题思路和洛谷P2440有点像,建议先看P2440这个题,较简单。 二分答案 题目详见洛谷P3853路标设置 思路 建议先看这里,我的另一个博客 这里先贴段代码 bool check(long long length) { int num = 0; int now = 0; for(int i = 阅读全文