*[hackerrank]Tree Covering】的更多相关文章

https://www.hackerrank.com/contests/illuminati/challenges/tree-covering 这道题先是在上次交流讨论了一下,然后两位百度的朋友先写完代码share出来了,觉得是道很好的题,就做了一下.https://gist.github.com/coder32167/6964331 https://gist.github.com/snakeDling/6965299基本思想是贪心.根据题意,所选的点必然是叶子节点,那么首先找出树的直径,直径上…
regex: https://github.com/taiyang-li/hackerrank/tree/master/hackerrank/regex-exercise awk: https://github.com/taiyang-li/hackerrank/tree/master/hackerrank/awk-exercise sed: https://github.com/taiyang-li/hackerrank/tree/master/hackerrank/sed-exercise…
Introduction There is a common understanding that a single snapshot of the java heap is not enough for finding a memory leak. The usual approach is to search for a monotonous increase of the number of objects of some class by “online” profiling/monit…
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…
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为根的子树对应…
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…
A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/tree/master/hackerrank/algorithms/the-indian-jobLesson learnt: The Italian\Indian job is two-way 01 Knapsack. And some complext problem can be convert…
The most interesting, flexible and juicy binary tree problem I have ever seen. I learnt it from here: https://codepair.hackerrank.com/paper/5fIoGg74?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6IkJsdWVCaXJkMjI0IiwiZW1haWwiOiJoZWFsdGh5dG9ueUBnbWFpbC5jb20ifQ%…