*[hackerrank]Cut the tree】的更多相关文章

https://www.hackerrank.com/contests/w2/challenges/cut-the-tree 树分成两部分,求两部分差最小.一开始想多了,后来其实求一下总和,求一下分部的和就行了. #include <cstdlib> #include <climits> #include <algorithm> #include <iostream> #include <vector> using namespace std;…
题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a,b)的时候,其中的一棵树必是以a或者b为根的子树,那么我们就可以知道生成的两棵树的节点之和了.所以,当我们得到以每个节点为根的子树节点和这个信息后(把这个信息存储在TreeNode的value变量中),通过遍历每个节点(每个节点为根的子树必然为某次cut得到的子树之一,例如下图中,2为根的子树对应…
Something to learn: Rotation ops in AVL tree does not require recursion. https://github.com/andreimaximov/hacker-rank/blob/master/data-structures/tree/self-balancing-tree/main.cpp node *create_node(int val) { node *pNew = new node; pNew->val = val; p…
The Utopian tree goes through 2 cycles of growth every year. The first growth cycle of the tree occurs during the monsoon, when it doubles in height. The second growth cycle of the tree occurs during the summer, when its height increases by 1 meter.…
Learnt from here: http://www.cnblogs.com/lautsie/p/3798165.html Idea is: we union all pure black edges so we get 1+ pure black edge groups. Then we can simply pick only 1 vertex from each pure-black group to form a triangle. Then it will be all combi…
the apple tree A long time ago, there was a huge apple tree. A little boy loved to come and lay around it every day. He climbed to the tree top, ate -the apples, took a nap under the shadow... He loved the tree and the tree loved to play with him. Ti…
factoextra is an R package making easy to extract and visualize the output of exploratory multivariate data analyses, including: Principal Component Analysis (PCA), which is used to summarize the information contained in a continuous (i.e, quantitati…
In a training session, the trainer asked the audience "knowledge is power, how many of you agree" almost everyone agreed, the trainer said "not true, knowledge is not power, applied knowledge is power". No matter what we learn, the ult…
1 compress & mr hive默认的execution engine是mr hive> set hive.execution.engine;hive.execution.engine=mr 所以针对mr的优化就是hive的优化,比如压缩和临时目录 mapred-site.xml <property> <name>mapreduce.map.output.compress</name> <value>true</value>…
Day -1 在机房颓颓颓颓颓,晚上得知这次考试题本来是要给 ZJOI2018 用的,结果没用上..可想而知考试的难度.. 但愿不爆零 Day 0 坐了一上午火车,顺便找茁神犇拷了个 COD,然后接着坐大巴.实在是太困在大巴上睡了一觉.坐在姚神犇旁边感觉 rp++. 下午我们是鸡试机,敲 splay 敲了一半弃了,然后改敲线段树..最后写了个 A+B 对拍玩了玩 Google Chrome 的小恐龙就走了. 晚上在宾馆颓颓颓颓颓,旁边颜神犇在码数位 DP ,自己在玩 COD... 真是自愧不如啊…